Advertisement

Custom Game Script Compilers

Started by January 05, 2001 09:14 PM
6 comments, last by wannabe H4x0r 24 years ago
Okay, I think I am venturing into a field to advanced for one such as myself but I''m going to ask this anyway: How do games compile external scripts during runtime: i.e. Quake-C or UnrealScript
theres a series of articles going on here, i''m sure reading it would clarify things for you..
heres a link for the first of the three articles
http://www.gamedev.net/reference/programming/features/scripting1/
Jonas Meyer Rasmussenmeyer@diku.dk
Advertisement
uh... see the problem is that I graduated from VB to C++ about 3 years ago and I''m trying to figure out how to do somethin actually efficiently.

sorry if u use vb but its fine for like turnbased stuff but for actual gfx crunching and stuff, u need something that u can take to a lower level, closer to the win API and maybe the system metal itself.

can somebody help me w/ like C, quake/unreal style lightning-fast scripting? Im actually making an RTS, but I want to make it MOD-able, so same idea... u know.

thanx

Well, I would go with an external compiler that compiled p-codes for a virtual machine(easier to compile, easier/faster to interpret, and can support high-level constructs of the language easier...). I think that''s how most of them go about it. Some wankers just use .DLL''s and say "screw it", and let people use C(has nasty safety-side effects, probably easier to implement at first, but a later cause of headaches, Quake II worked this way I believe).


A good set of references, discussion, and articles about all kinds of programming language development is at my site http://tos.maintree.com/babel.

Not to discourage you but writing your own programming language or even scripting language, is no easy feat. If you are serious though, I''d recommend learning about how to parse a file and break it into tokens. There are programs available out there that will do this for you after you supply a ''language definition'' but I find those programs take away a lot of the fun (they are named lexx, yacc, bison etc).

The next thing to work on is syntax checking. You need to decide whether you want to use recursive descent or a shift reducing technique (which is faster and more efficient but harder to write).

The next thing to learn is how to build a symbol table and define an intermediate code format. If you are writing your own bytecode you need to write a virtual machine (which entails learning about memory management/garbage collection, exception handling etc).

I''ll try to dig up resources on this relatively obscure topic. If you want to get started now check out FlipCode and look for the scripting tutorial there.

Hope this helps.

Dire Wolf
direwolf@digitalfiends.com

P.S. Do yourself a favour and start small. Don''t try to write something as complicated as a full language the first time around. Write something simple that can maybe do simple loops, and maybe print strings etc. Then progress to variables. Lastly tackle functions and if you are feeling confident classes, templates and function overloading (if your language requires that).

[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
ok... this sounds like a real pain in the ass. how about just having my basic program (it has all the ''core'' information like where object 1 of type A is on map B) link to an DLL that specifies what object 1 of type A will do.

I think this is how half-life does it because in my cstrike directory and stuff, every game mode (mod) has their own client.dll which i would assume is the code.

so... how do u switch which dll u link to during runtime?
Advertisement
You can use the Win32 command LoadLibrary() and then GetProcAddress().



typedef (IObjectFactory*) (*GetObjectFactoryInstance)();

HMODULE hDll = LoadLibrary("c:\\myfile.dll");

GetObjectFactoryInstance = GetProcAddress(hDLL, "GetObjectFactoryInstance");

IObjectFactory* pObjFactory = GetObjectFactoryInstance();
IObjectMap* pObjMap;

pObjFactory->RegisterObjects(pObjectMap);

IObjectA* pObjA = pObjMap->Create("ObjectA");
IObjectB* pObjB = pObjMap->Create("ObjectB");

// run your game and at end of game...

// you shouldn't call delete on a pointer from a DLL. So let the object handle its own deletion - very COM-like.

pObjA->Release();
pObjB->Release();
pObjFactory->Release();

FreeLibrary(hDll);



If you program your client using abstract interfaces and place the implementation of the interfaces in a DLL you can change the implementation of ObjectA by just changing the DLL (not at run time though! - there is a way to do that but its more involved and typically not necessary).

Ah the power of interfaces

I hope this helps you.

Dire Wolf
direwolf@digitalfiends.com

Edited by - Dire.Wolf on January 6, 2001 6:31:19 PM
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
You could try an external scripting library. Quite a few exist out there, some better than others. Currently, the one I plan on using in my game is Seer (available here). It allows for external script files that can be interpreted on the fly or pre-compiled. Script syntax is essentially the same as C. I''ve little experience with it yet but it seems good.

-Goku
SANE Productions Homepage

This topic is closed to new replies.

Advertisement