Let's say I have a game written in C++. But I want to add some modding or scripting functionality to it. How would one go about adding a scripting functionality to your game?
feedback
|
First of all, you should decide what part of your game is scripted. One option is to have a fully scripted game in the sense that while the time-critical backend operations are coded in C++, all the game logic is in the scripting language. Designers use the backend as a library called from the high level scripting language. On the other extreme, you can have few specific places where scripts are used, such as the user interface or scripted sequences, with the majority of the game code is still in C++. There are advantages to each approach (speed, flexibility, compilation time, scope of game, etc.), but you need to decide that beforehand. Once you know how you want to use scripting, you now need to decide if you're going to use an existing scripting language or your own. Today there are many scripting languages to choose from with different design goals and target audiences, so I'm not sure if it's worth creating your own anymore. You can read about implementing your own scripting engine here. Some popular scripting languages include Lua, which is lightweight and easy to embed. It uses a stack for communication between the host and embedded language and it was successfully used in many professional games. Another option is AngelCode, which allows you to call C and C++ functions directly. Python and Ruby are a bit more complex to embed but once you have done that they are very pleasant to program in. If you want to embed Python then take a look at Boost.Python. You can also try embedding JavaScript and take advantage of the fast scripting engines developed for browsers. For my game we are using Google's V8 engine which is very fast and easy to embed, but Mozilla's SpiderMonkey is another option. | |||||||||
feedback
|
The most popular language: See Lua (Programming language) Example: IBM has a great article on this: Embedding LUA | |||
feedback
|
I wrote a post about embedding GameMonkey script to a game using DragonFire SDK here: http://bit.ly/96vndP Basically the idea is to expose your C\C++ functions to your chosen scripting language and use them from your script. In my tutorial, I exposed 2 functions from DragonFire SDK. At game start, I call onStart function from script and on update, I call onTimer function from script. Hope that helps! | |||||
feedback
|