Skip to main content
gamedev.net
🔒 Locked

what scripting engine should I implement?

Started by DarkSlayer Jul 13, 2004 at 11:19 AM 13 replies 2.3k views
Original Post
DarkSlayer
DarkSlayer
I'm interesting in creating an script engine for my game. I am currently reading and searching alot, and tries to design as much as possible(to avoid to many restarts which I have had before). I have a need of configure the engine, like creating and loading "objects", setting the graphic info, key and mouse setup, physics setup, etc etc ...this seems kinda ok, probably difficult, but using ini files of some sort will do. Like the ini coding in C&C Generals. But I could also have a need for creating a bit more advanced scripts with variables, loops etc etc. I could use it for AI, Story Handeling, and maybe a few other needs. Then you of course have the plugin stuff ... not sure if I need it quite yet, but if I would like to feed the renderer with new shaders and stuff ... maybe plugins are better than scripting? .. .not sure. I'm planning to look into that as well Then of course ... how do I create this script engine? One aproach is creating a JIT compiler or Vitual machine ... which looks very difficult. Thats the approach from several links and articles here. What other options do I have? And would I be able to deal with large scripts (like story stuff), that will have to be in their own threads? Then I could have a use of letting the scripting system be able to use stuff from plugins. 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??
DarkSlayer
DarkSlayer
but lua and small runs pretty much as a jit compiler?+?? hmm... this might seems a lot of work
Monder
Monder
Quote:
Then you of course have the plugin stuff ... not sure if I need it quite yet, but if I would like to feed the renderer with new shaders and stuff ... maybe plugins are better than scripting? .. .not sure. I'm planning to look into that as well


Have both plugins and scripting. You'd use a plugin for something speed critical such as a new rendering subsystem (e.g. you'd have one for OpenGL and one for DX), while scripts would be used for handling high level things.

Quote:
but lua and small runs pretty much as a jit compiler?+?? hmm... this might seems a lot of work


The LUA API is pretty simple, you don't need to know anything about how they work internally to use them. Using LUA would certainly be less work than creating a new scripting language (as you seem to be wanting to do).
DarkSlayer
DarkSlayer
ok - I'll look into it. I am just afraid to either aim to high on a script system that will complicate a lot when creating the game engine, or developing something that ends up as a huge limit to the engine(i.e. have to rebuild and redesign the entire engine)
evolutional
evolutional
&#106avascript is my current choice.

There's also GameMonkey, which is a mix of Lua and C++-like syntax.

As well as AngelScript, the author of which is a resident of these fora.

There's plenty others too (Python, Ruby, Tcl, etc) or you could roll your own :)

As I said, my personal choice is &#106avascript and I'm finishing up a tutorial &#111;n using it in games - <a href="http://www.evolutional.co.uk/jsi">jsInvaders</a>.<br><br>Whichever &#111;ne you choose, make sure you base your choice &#111;n how you feel with the language and the implementation (ease of use for you is important) - not just because it's cool to go &#111;ne way.<br><br>[smile]
DarkSlayer
DarkSlayer
I have seen all the recommendation of languages to use in this forum, but I have not had a good look at them.

What syntax it is using is probably not the most important, I guess most languages will do. But my experience with scripting is kinda "extremly very low".

As I said. I am at a stage where I am trying to draw, and plan as much as possible, make choises over what kinda tech I want in my engine. Then my goal is to create some sort of a framework and a plan to work with. As you stated, ease of use and implementation is kinda important.

but I have to say ... I am very impressed with the fast response I get at this forum.

thx alot
Raduprv
Raduprv
Just embed Small. It's a great scripting language, with a JIT compiler (no, LUA doesn;t have a JIT, at least not AFAIK), so it's very fast. It's also C like, so if you already know C you won't need to learn a whole new syntax and grammar.
evolutional
evolutional
If learning to use and embed a range of script languages is your goal, one thing that you could consider is developing a form of abstraction layer for scripting. I've been toying with this idea myself, essentially building another interface layer on top of the scripts which totally shields the game developer from things like LUA stack manipulation, variable casting and the like. I've already started something similar, at least to some extent by splitting game code from specific script language code. For example, I don't want to have to worry about mixing JS_* calls with my internal system works, because what happens if I want to switch to LUA in the future? All I need to do with my current system is rewrite the scripting API component (which is game specific) to change from using JS_* calls to using lua_* calls. I was thinking, I could possibly abstract this further, so the game calls things like Script->SetVar(x,y) and the abstract plugin system will deal with such calls in it's own specific language. This is something I'll probably work on after jsInvaders has finished.
exa_einstein
exa_einstein
use python, it is not very hard to implement into C++, but it is quite slow so don't let the whole engine/game be executed from python's core
(probably you also could use BOOST)
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.
DarkSlayer
DarkSlayer
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.
exa_einstein
exa_einstein
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.
Monder
Monder
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).
DarkSlayer
DarkSlayer
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.
Monder
Monder
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.