In-game scripting and what should be done

BlitzMax Forums/BlitzMax Programming/In-game scripting and what should be done

Dubious Drewski(Posted 2005) [#1]
I'm currently giving my game the ability to read scripts
from a file during runtime, then execute them. This will be
used for cutscenes, etc. The script will activate events
which are hard-coded into the program. Events will tell a
character to go here or say this or kill that, etc. I have
almost completely fleshed out the system on paper, but
one question remains. How do I write these events into
the program?

Currently, the only system I can come up with is:

Repeat
	If event[1] = ACTIVE Then
		doSomething()
	EndIf
	If event[2] = ACTIVE Then
		doSomethingElse()
	EndIf
Forever

And Then have functions that correspond To them:

Function doSomething()
	make main character walk over there
EndFunction
	
Function doSomethingElse()
	turn the snow level And windspeed up
EndFunction


This is such a hack-job and I hate having to do it like this,
but I don't know how not to have events hard-coded.

Is this the sort of thing that Lua handles well? I'm
completely unfamiliar with it at the moment.


GW(Posted 2005) [#2]
If you want a true scripting system then your options are LUA and the upcoming BVM v2.0

LUA already comes with BMAX. But BVM's binding functions are the greatest thing since sliced bread imo.


Rimmsy(Posted 2005) [#3]
Have a look at LUA. It's fantastic. As soon as you've got a groundwork to build on you can do just about anything. There is one problem though. It's extremely hard to debug in bmx at the moment (at least for me anyway).

You bind your bmx functions to LUA so it can use them. You can also go the other way. For simplish things like the ones you've outlined above, LUA would be perfect fo you.

http://www.blitzbasic.com/Community/posts.php?topic=52524

Noel's the bloke to talk to about this.

Here's a quick example:



Hotcakes(Posted 2005) [#4]
your options are LUA and the upcoming BVM v2.0

I wouldn't put off any project waiting for BVM2. Use Lua and maybe down the track expand into BVM but it's not really an option any time soon.


Ferminho(Posted 2005) [#5]
I've been doing something similar to your script system for some time... This is what I do.

My game always has a script file open. Events are not hardcoded, they are scripted (well, the 'trigger' IS hardcoded). There is a set of script functions, being some of them like this:

event_timer 1000 label1

this enqueues an timer-trigger activated event. 1000 ms later of reading this line, the parser will jump to label1 and will start parsing. There are other kinds of events like on_die ID, enters_zone ID X1 Y1 X2 Y2... etc

There has to be a mode to tell the parser "stop parsing and continue when some event is triggered". In my case the function 'stop' does this. So a simplified script would be like this:

fade_off
load_map "blah"
put_camera 50 50
put_text 1 "Green Hill"
fade_on
event_timer 2000 start
stop

.start
spawn_char 50 50
delete_text 1
stop

It's just an example of how it works -more or less-, didn't use actual script code.
And there is the fact that I don't parse script directly, I compile it to a bytecode for faster in-game parsing.

Notice that my script is not only for cutscenes, but for any kind of ingame event, changing music, spawning enemies, vehicles, etc. That's why a script file is always open and ready to parse any moment.

Nevertheless, although I don't use it for my own reasons - LUA is surely a better choice.


Dubious Drewski(Posted 2005) [#6]
You guys are always so helpful. I appreciate it. I don't have
time to learn Lua in a week, so I will have to use my
hack-method for now. But after this Hellish rush I'm in is
over, I'm coming back and trying Ferminho's variation, and
then maybe some Lua.

In case you're wondering, I am writing the code for this
game while someone else(a non-programmer) is supposed
to convert his story and cutscenes into game script. So I
need to keep the script very simple to understand.


ImaginaryHuman(Posted 2005) [#7]
You can always make your own system. I have a custom script system I'm using based on executing functions.