Pre-made scripting engines?
I was in a discussion in the Game Programming subforum here, and it was reccommended that I ask about pre-made scripting engines. Where can I go to find out more about scripting engines (where they can be found pre-made, or perhaps how to make one)? I''m new to the concept of scripting as well, so any resources about the theory and application of scripting would be helpful as well! Thank you very much for your time! =)
-Vendal Thornheart=) Programming for a better tomorrow... well,for a better simulated tomorrow. ;)
Well, for starters, I guess the two main contenders are Python and Lua.
While both of these are also implemented as stand-alone interpreters for executing "pure" scripts or programs, they also include components for linking, or embedding, into a project.
Typically, the process for implementing in-game scripting for either is similar. Mechanisms are provided for "exposing" certain of the functions, classes, constants, etc... in your game engine to be available to the script interface. Functions are provide for executing scripts from within the game environment, whether by executing string or character buffers, external script files, or whatever.
The main library components provide the functionality for reading in a file, a string or a character buffer containing a script''s program code, parsing it and executing the resulting virtual machine code, performing the specified operations within the context of your game engine. Scripts can call functions exposed to the script interface, can instance objects of classes it knows about, can access constants and globals if they are made visible, and so on.
Typically, scripts are executed by various "hooks" in the engine code. For instance, a magical trap of some sort might have a hook associated with a player proximity sensor; when it senses that the player is within triggering range, the corresponding script (probably stored as a character buffer, preloaded from file) will be executed to implement the trap''s behavior. You can implement script hooks for pretty much anything you can imagine--AI thinking hooks, level heart-beat hooks (for instance, to generate random monsters periodically), spell effects, item usage, etc... By defining the behaviors in script, it is easier to make changes to behaviors even while the engine is still executing, rather than having to recompile and restart.
Due to the simpler organization of embedded languages in comparison to C/C++, and also due to the fact that the embedded language runs on a layer higher than the machine code of compiled C/C++, you have to jump through a few hoops to make C/C++ implemented functions available for use in script. Each language will have a slightly different mechanism, but common principles are shared.
There are tools available for the common languages to ease the task of creating the "binding" code that exposes interface to script. These automate the process of creating the glue code, allowing you to specify the interface and let the tools handle the repetetive details. You can find details of these at the websites named above, or in the general community around a specific language.
There are other alternatives as well, such as Tcl, but Lua and Python seem to be the most popular among game developers around here.
Check out the above websites, and the articles about scripting in the GameDev.net Articles and Resources section to learn a bit more. There is one there, an article by Ash Matheson, that will hold your hand and guide you through the beginning steps of embedding Lua into a project. You might find it enlightening.
Anyway, good luck and have fun.
Josh
vertexnormal AT linuxmail DOT org
Check out Golem: Lands of Shadow, an isometrically rendered hack-and-slash inspired equally by Nethack and Diablo.
While both of these are also implemented as stand-alone interpreters for executing "pure" scripts or programs, they also include components for linking, or embedding, into a project.
Typically, the process for implementing in-game scripting for either is similar. Mechanisms are provided for "exposing" certain of the functions, classes, constants, etc... in your game engine to be available to the script interface. Functions are provide for executing scripts from within the game environment, whether by executing string or character buffers, external script files, or whatever.
The main library components provide the functionality for reading in a file, a string or a character buffer containing a script''s program code, parsing it and executing the resulting virtual machine code, performing the specified operations within the context of your game engine. Scripts can call functions exposed to the script interface, can instance objects of classes it knows about, can access constants and globals if they are made visible, and so on.
Typically, scripts are executed by various "hooks" in the engine code. For instance, a magical trap of some sort might have a hook associated with a player proximity sensor; when it senses that the player is within triggering range, the corresponding script (probably stored as a character buffer, preloaded from file) will be executed to implement the trap''s behavior. You can implement script hooks for pretty much anything you can imagine--AI thinking hooks, level heart-beat hooks (for instance, to generate random monsters periodically), spell effects, item usage, etc... By defining the behaviors in script, it is easier to make changes to behaviors even while the engine is still executing, rather than having to recompile and restart.
Due to the simpler organization of embedded languages in comparison to C/C++, and also due to the fact that the embedded language runs on a layer higher than the machine code of compiled C/C++, you have to jump through a few hoops to make C/C++ implemented functions available for use in script. Each language will have a slightly different mechanism, but common principles are shared.
There are tools available for the common languages to ease the task of creating the "binding" code that exposes interface to script. These automate the process of creating the glue code, allowing you to specify the interface and let the tools handle the repetetive details. You can find details of these at the websites named above, or in the general community around a specific language.
There are other alternatives as well, such as Tcl, but Lua and Python seem to be the most popular among game developers around here.
Check out the above websites, and the articles about scripting in the GameDev.net Articles and Resources section to learn a bit more. There is one there, an article by Ash Matheson, that will hold your hand and guide you through the beginning steps of embedding Lua into a project. You might find it enlightening.
Anyway, good luck and have fun.
Josh
vertexnormal AT linuxmail DOT org
Check out Golem: Lands of Shadow, an isometrically rendered hack-and-slash inspired equally by Nethack and Diablo.
Very interesting! =) Thank you for your response, it has helped greatly in my understanding of where scripting fits in. I see that it''s probably going to take a while until I get used to how it all fits together, but conceptually it''s starting to come together. Thanks! =) =)
-Vendal Thornheart=) Programming for a better tomorrow... well,for a better simulated tomorrow. ;)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement