Advanced Scripting Engine

Community Forums/Showcase/Advanced Scripting Engine

Klapster(Posted 2003) [#1]
For my RPG that is currently in development I decided that scripting is the way to go (as is almost always the case for RPG's)

The main engine of the RPG is almost complete and I finally completed the scripting engine, which was in my opinion the main hurdle.

I wanted to make the scripting engine as flexible as possible and to allow syntax almost as complex and complete as that of blitz. The hardest thing to do was allowing nested procedures and nested conditional statements, etc at the lexical analysis stage.

To do this I used a recursively defined procedure that entered a new recursion each time a parameter is encountered while linking each recursion to the last.

Anyway, the following is an example script that my engine can handle perfectly and at very little speed loss: -

;Initialise Map
if getvar[`doonce`]!`TRUE`	
	playmusic[`BGM2`]
	loopsound[`waterfall`,`520`,`800`,`1`]
	createentity[`Ryu`,`player`,`80`,`200`,`ryu`,`1`]
	createentity[`Zena`,`dude`,`160`,`200`,`zena`,`1`]
	createentity[`Mcdohl`,`mcdohl`,`920`,`360`,`mcdohl`,`1`]
	movemode[`player`,`control`]
	follow[`player`]
	global[`counter`]
	setvar[`counter`,getvar[`counter`]+`1`]
	textbox[getvar[`counter`],`3`,`player`,`player`]
	textbox[`Wow, this place is real pretty!`,`3`,`player`,`player`]
	screengoto[`600`,`600`,`1`]
	waitevent[]
	textbox[`Coool! Look at that waterfall!`,`1`,`player`,`player`]
	screengoto[`400`,`800`,`1`]
	waitevent[]
	follow[`player`]
	textbox[`Ooooh, who's that?`,`3`,`player`,`player`]
	setvar[`doonce`,`TRUE`]
endif

;Talking to Mcdohl
if entitycollision[`player`,`mcdohl`]=`1`
	if keydown[`28`]=`1`
		setvar[`mcdohltalk`,getvar[`mcdohltalk`]+`1`]
		select getvar[`mcdohltalk`]
			case `1`
				textbox[`Hiya, how you doin'?`,`3`,`mcdohl`,`player`]
				textbox[`I'm not too bad thanks Mcdohl!`,`1`,`player`,`mcdohl`]
			case `2`
				textbox[`Look I've had enough of you Ryu.\Speak to me once more and I'll teleport you!!`,`3`,`mcdohl`,`player`]
			default
				textbox[`RIGHT THAT IS IT, YOU ARE GONE!!`,`2`,`mcdohl`,`player`]
				changemap[`test2`]
		endselect
	endif
endif

;Talking to Zena
if entitycollision[`player`,`dude`]=`1`
	if keydown[`28`]=`1`
		setvar[`zenatalk`,getvar[`zenatalk`]+`1`]
		select getvar[`zenatalk`]
			case `1`
				textbox[`Hello Ryu, how are you today?`,`1`,`dude`,`player`]
				textbox[`I am fantastic thank you Zena. Nice weather today, isn't it?`,`3`,`player`,`dude`]
			case `2`
				textbox[`Hey, haven't I spoken to you already today?`,`3`,`dude`,`player`]
				textbox[`Yeah, probably...`,`2`,`player`,`dude`]
				textbox[`Bye!`,`3`,`dude`,`player`]
				follow[`dude`]
				goto[`dude`,`360`,`1400`]
				waitevent[]	
				follow[`player`]
				textbox[`Crickey, what a prat!`,`3`,`player`,`dude`]
			case `3`
				textbox[`Jeez, quit following me won't you!`,`3`,`dude`,`player`]
				textbox[`Hey! Hang on a minu....`,`1`,`player`,`dude`]
				playmusic[`BGM1`]
				weather[`rain`]
				loopsound[`waterfall`,`-1`,`-1`,`0.1`]
				follow[`dude`]
				goto[`dude`,`360`,`200`]
				waitevent[]
				follow[`player`]
				textbox[`Damn it!`,`3`,`player`,`dude`]
			case `4`
				textbox[`Look I'm sorry, now, please move!`,`3`,`player`,`dude`]
				textbox[`Ok, Ok I'm going`,`1`,`dude`,`player`]
				goto[`dude`,`600`,`200`]
				waitevent[]
			default
				textbox[`Oh just go away!`,`3`,`dude`,`player`]
		endselect
	endif
endif


Obviously the actual commands shown in the above example are specific to my own RPG, however the commands and their action can easily be changed.

Summary of the features: -
* Inline Comments
* SELECT CASE DEFAULT conditional statements
* IF ELSE conditional statements
* Easily customisable command set
* GLOBAL and LOCAL variables
* Practcally Infinitely (up to the limit of Blitz's recursion stack) nested procedures and conditional statements.
* Powerful realtime math evaluation allowing nested brackets and all standard mathematical operators.

The point of this post was to see if anyone would be interested in licensing this scripting engine. I'm thinking about allowing a few people access to the code and rights to use it in a project for a small fee.

Anyone interested?


(tu) sinu(Posted 2003) [#2]
i'd be interested, i've just been reading up and trying to do a basic scripting language.


Sunteam Software(Posted 2003) [#3]
Good luck with it, I was working on one myself for our Action Adventure, however it turned out that we would have actually not gained much from doing it so we've ditched it now and are continuing with standard development techniques. Overall I don't think our game will be logistically complicated enough to warrant scripting, but hats off to anyone doing it as I know how much work it requires :)


Klapster(Posted 2003) [#4]
Thanks :) I'm set on using scripting for my RPG because it feels so much nicer having everything to do with the maps seperate from the main engine code.

Also, another guy is developing the storyline and it's nice to let him experiment with creating maps and scripts without actually having to play with the main engine code. When I release an update for him, he can simply reuse his script without having to re-write the code into the engine update.


Klapster(Posted 2003) [#5]
Hiya Sinu, I tried emailing this to you, but it said that your email address (srndrskh@...) does not exist.