Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Game Scripts -- Runtime Compilation

This topic is 5751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
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)

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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:


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.

Share this post

Link to post
Share on other sites
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?

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!