Advertisement

what scripting engine should I implement?

Started by July 13, 2004 11:19 AM
13 comments, last by Monder 20 years, 4 months ago
evolutional: not 100% sure what you are thinking about. Are you thinking of having a layer between the script engine/component (that can be any language), and the game engine? and when you change language you just change that layer?

...quite a job.

I'm currently waiting for a couple of books I found recommended on this forum. I still don't know how to "attack" my problem of HOW to implement a language. It looks like I have to do a VM, or JIT or something like that. I cant find info about anything else.

Except for the tutorials here, peroxide and flipcode... are there any other places that discuss scripting, or scripting in games? I am looking for how to design or create a framework where I can build my engine around. Have a few books, but they don't include much scripting

I'll think I have to do those tutorials before i ask more questions here, because I'm really lost here.
Quote: ..., because I'm really lost here.

read something about embedding, all these languages have something what connects them, then you will possibly be able to implement something like this:
class Script{public://construct/destructvirtual variable_type EvaluateExpression(char* code);virtual compiled_code_object PrecompileCode(char* code);virtual void RunCode(char*code);virtual void RunCode(compiled code object code);virtual void ClearGlobals();virtual void MergeVarsWith(Script* s);};//then you can derive:class PythonScript:public Script{static PyObject * globals;PyObject* locals;...};


Quote: And would I be able to deal with large scripts (like story stuff), that will have to be in their own threads?

do not use threads, try something like HL's "wait;"

When I was younger, I used to solve problems with my AK-47. Times have changed. I must use something much more effective, killing, percise, pernicious, efficient, lethal and operative. C++ is my choice.
Advertisement
Quote: I still don't know how to "attack" my problem of HOW to implement a language. It looks like I have to do a VM, or JIT or something like that. I cant find info about anything else.


If you don't make your own scripting language, then the implementation (e.g. things such as VMs and JIT compilers) is taken care of for you in the API you use to embed the scripting language.

Of course if you make your own scripting language you have to implement everything yourself, if you choose to take this route, there's some articles here which could help you out (in particular the 'Creating a Scripting System in C++' series of articles).
Monder: Ok, did read through the Creating a Scripting System in C++' series. Didn't have time to look through the code really well, need to go to work tomorrow.
But it looks quite ... simple (probably not, but I understood the concept). The last article was a bit difficult to really grasp, but I'm tired at the moment.

The part I am wondering about is the connection between the VM which is prosessing the script and the rest of the game engine. I have to read the last artickle about the callback stuff one more time. But is it so that I have to create the Game engine with the renderer, physics, etc etc inside the VM? or do I have to create a very elaborate layer between the VM and the Game Engine? My head is probably spinning now...

But a few questions.
No threads?? How would I then create several scripts, one for each special unit/npc that would do stuff in the background/offscreen. Lets say GTA3 where you could have a npc working or doing something on the other side of town ... then you spawn to that place ... and can see the progress of his work?

Let say I choose to implement small as a script language to my engine. Are there any game tutorials using this? Someone who would not recommend small? Am I missing out on something when using small?

I'll google some more tomorrow. thx alot by the way. You guys have been very helpful.
Quote: The part I am wondering about is the connection between the VM which is prosessing the script and the rest of the game engine. I have to read the last artickle about the callback stuff one more time. But is it so that I have to create the Game engine with the renderer, physics, etc etc inside the VM? or do I have to create a very elaborate layer between the VM and the Game Engine? My head is probably spinning now...


First of all the VM is what runs the script (well in some cases anyway), if you're not implementing your own scripting language (i.e. you use LUA or Python or Small or whatever) you don't need to worry about it.

To create a link between your script and the engine you have to register functions that your script can call and variables that it can access (and possibly change) to alter stuff. How you do this depends on the scripting language you're using. Here's a simple example, say you had an NPC that was waiting for a certain thing to appear before moving, if you had an Update function in the NPC's script you may write something like this (in Psuedo Code):

function Update( )   if(ThingExists)       MoveTo(40, 10)   end ifend function


ThingExists would be a variable you have registered that is true if the thing the NPC is waiting for exists. MoveTo would be a function that moves the current NPC (i.e. the one you've just called the update function for) to a different position.

Of course in a real game engine, you wouldn't have a variable registered such as ThingExists, instead you may have another function like IfObjectExists, which you could use to check the existance of a named object.

Quote:
No threads?? How would I then create several scripts, one for each special unit/npc that would do stuff in the background/offscreen. Lets say GTA3 where you could have a npc working or doing something on the other side of town ... then you spawn to that place ... and can see the progress of his work?


You do not need threads to implement something like this, just have something like an update function that is called for every NPC every frame, and functions that a script file can register as being called when events happen, e.g. an event could be when an NPC has reached a certain position. When this event happens a script function would be called and the NPC script would act upon it.

Quote:
I have seen many suggestions for languages, and thats ok... but I have to understand how I should implement this scripting before I choose language and stuff (a C like language would be nice) ... whats your opinions??


Even if you don't decide upon a language to use, at least take a look at one or two scripting language's API for embedding. It may give you a far better idea of how everything works.

This topic is closed to new replies.

Advertisement