Advertisement

Scripting Language Questions.....

Started by September 10, 2000 10:27 AM
0 comments, last by Mike 24 years, 3 months ago
I''d like to know if anyone knows of a good way to parse IF-THEN-ELSE statements. I''m open to any suggestions. Secondly I''d like to know if running a script every time through the game loop would cause a large performance hit. Before you answere that, here is an example to show how my scripting language works: An example script:

EXTERN

	FUNC PrintMessage[ STR:message ]
	FUNC MultiplyAndPrint[ NUM:a, NUM:b ]

ENDEXTERN

PROGRAM

	NUM total
	NUM x
	NUM y
	STR string

	PRINT "PLEASE ENTER A NUMBER FOR X:"
	INPUT x

	PRINT "PLEASE ENTER A NUMBER FOR Y:"
	INPUT y

	total = x + y

	IF total == 5 THEN
		
		string = total + " EQUALS 5\n"
		PRINT string

	ELSE

		string = total + " DOES NOT EQUAL 5\n"
		PRINT string

	ENDIF

	CALL PrintMessage[ string ]
	CALL MultiplyAndPrint[ total, total ]

ENDPROGRAM
 
This script is then converted to "virtual" assembly like so:

START:
	PUSH	PLEASE ENTER A NUMBER FOR X:
	PRINT
	PUSH	x
	INPUT
	PUSH	PLEASE ENTER A NUMBER FOR Y:
	PRINT
	PUSH	y
	INPUT
	PUSH	x
	PUSH	y
	ADD
	PUSH	total
	ASGN
	PUSH	5
	PUSH	total
	CMP
	JNE
	PUSH	 EQUALS 5

	PUSH	total
	ADD
	PUSH	string
	ASGN
	PUSH	string
	PRINT
	JMP
LABEL	
	PUSH	 DOES NOT EQUAL 5

	PUSH	total
	ADD
	PUSH	string
	ASGN
	PUSH	string
	PRINT
LABEL	
	PUSH	string
	CALL	PrintMessage
	PUSH	total
	PUSH	total
	CALL	MultiplyAndPrint
 
I plan to use this in a 2D game and since the script is simply exicuted by going through the op codes and colling "execute" I don''t see how it sould cause a problem. I''m just looking for other opinions. Obviously the example above is not to be used a script in a game. It''s just one I wrote to test the language thus far.
as for if/else statements, just have a function to scan for a string, and then pull a
scan("else") if the if test fails. I would simply take the next else (unless you use parenthesis or something).

the performance depends on the script and the computer running it, i don''t think that little bit will be noticable compared to 600 blts+ a second with a 2d game.
___________________________Freeware development:ruinedsoft.com

This topic is closed to new replies.

Advertisement