- Scripting languages are generally used for making ‘things happen’ in the game world. For example “when the player walks here, make the enemy appear”, “after this much time has passed, play this sound”, “if the enemy loses 50% of his health, tell him to start using his special attack move”.
- Looking at these types of needs, you can see how they’d fit quite nicely into code. They read like if..then statements, followed by function calls. But it’s also pretty simple, it seems we could live without templates, intrinsics, header files, operator overloading, and other advanced language features.
- To integrate the scripting engine into the game, and have the scripts be capable of doing useful things, the programmers have to wrap C/C++ functions in a way which makes them callable from the script. Also the programmers have to provide a way of launching scripts when certain events happen. To take the first example above, when the player enters a trigger volume, it must be capable of launching a script. In that script, the script would then make a call on the engine to tell a specific enemy (perhaps by a name in a string) to appear. A pseudo code script could look like this:
EnemyAppear ( “Enemy62_Soldier” )
- As the game is going to have lots of this type of game logic by the time it ships, it would be nice if we kept all this game specific hackery away from our nice clean game engine. Putting it into script files separate from the engine code makes the division nice and clear.
- If you use a simple language, someone who’s not a programmer could write the scripts. This can save valuable programming time, and give the game designers greater control.
- The scripting languages can either be interpreted at run time, or recompiled without the game engine stopping. This means that you could run the game once, and then repeatedly iterate on the scripts without having to restart the game. This can give a big saving on iteration time, compared with stopping the game, recompiling, and re-running.
- As open source scripting languages have already been developed and used on many other products and platforms, you can very quickly integrate a feature rich scripting language into your game, without having to build and debug your own.
- Scripting languages give you a bunch of basic features like variables, math functions, and string handling functions. These might sound like trivial features, but a common alternative to scripting languages struggles to replace these pieces of functionality.
Well that sounds great! You’d be crazy not to use them :)
Next time I’ll go through some of the down sides of using a scripting language.