Game Scripts -- Runtime Compilation

Started by
4 comments, last by zackriggle 21 years, 6 months ago
Alright, so maybe scripting is a bit harder than I could have ever dreamed (so far ). What I need help with is: How do I make a variable handler, that is, when the script-maker declares a variable, how do I make it at runtime? Also, when he wants to use the value in that variable, how do I retrive the value? Reading commands from file is the worst of my worries (although it is still one of them). Also, I want to know how I would go about allowing the user to create his own functions, and actually have the game recognize it. I think this would be worked into the variable handler, or something entirely different. If I have not lost you yet, please gimme some help. It''''d make our lives a hell of a lot easier
Advertisement
Scripting tutorial thingie
Domine non secundum peccata nostra facias nobis
lots and lots and lots of ways.

the most direct and fastest is to complie the "scripts" into a run time .DLL

but I''m assumeing you want to run them through an interpreter within the game engine....and there are lots of ways to do this.

purhapse the simpleist to develop is something like interpreted assembly...actually you could combine this with a "script compiler" to translate and store the script in a binary format before it is loaded into the game...actually this is simpler then it sounds....but you''ll have to do some research on how the CPU works and stores variables...I suggest you look into RISC chips...how they use "opcodes" and so fourth...simply because they can be a whole lot easyer to manage...essentualy when you are done with this you will have a "emulator" for a non-existant chip of your own design (your scripts can be thought of as emulator ROMS

Um...you will also want your game engine to have the power to stop the processing of the scripts (both..in case they contain infinate loops and/or so the engine has time to do a update or two before continueing to run the script)...heck if you do it right the entire game could run off scripts...leaveing the game engine to handle file loading, graphics, sounds, and player input (but useing scripts to determine what the input does)...which is pretty much what games like Quake do

It really is easyer then it sounds...you just got to keep in mind that this is a "virtual" chip and partition the memory accordingly (again look at how emulators work)

Actually, in Quake it''s compiled into a game DLL. An example for what you intended would be Dark Forces II: Jedi Knight. Nearly everything in that game is a script, from the weapons to playing the walk animation.
Does your script language include arrays or pointers?

I wrote a C-based script compiler/VM as part of my senior project...

I ended up compiling down to a linked list of instruction objects that looked a lot like assembly language. My engine was set up to handle all of the features of ANSI C (except for variable value initialization, which became very hard to do with arrays and structs due to a mistake in design)

When I compiled a script, one of the things I generated was a variable list for each compound statement. (A compound statement is almost any { } block of code in C). When the VM got around to executing one of the compound statements, a Variable object would be created for each entry in the variable list.

As for USING the variable, I had the compiler create a "PushVar " instruction. (My entire execution cycle works like RPN calculators).

So if you had:

{
int I;
I = 5*15;
}

The instructions would be:

PUSHC 15
PUSHC 5
MUL
PUSHV "I"
SET

I didn''t do any optimization... that was a little beyond me. I used YACC to generate a .v file, and wrote a converter to turn that into a nicer table than what YACC will output. Of course, I had to write all of the code outside of YACC because of this.
With all the talk about Virtual Machines, nobody''s used the word byte-code yet. Anybody know of any good resources to check out to build a virtual machine/create a virtual assembly language?
Aaargh! Everyone save your workspaces before your program locks up your computer!

This topic is closed to new replies.

Advertisement