Sep
25
Scripting
Filed Under Everything |
Pretty well any major game needs some sort of scripting ability. You may be able to get by without it in some very simple games, but even, say, a classic shoot-em-up could benefit. Think, for instance, of scripted boss battles. You may well disagree, and that’s fine, but I’m going to leave it at that.
So now that we all agree (it was my persuasive argument, wasn’t it?), we’re going to consider some of the options for adding scripting abilities to a game engine. Along the way, we’ll add some scripting abilities to Bayts. In particular, we’ll make it possible to create new steering behaviors using script.
As with most things, there are really two main options for adding scripting support to your game. Use a pre-existing, off-the-shelf solution, or develop your own. Several more decisions have to be made once you pick one of those two options, but that’s where it all starts.
If you’ve read any of my previous posts, you’ll probably guess that using an off-the-shelf solution would be my preference. You may be right but, more than most situations, this one is not quite so clear-cut.
For one thing, even if you use an off-the-shelf solution, it’s not actually going to work out of the box. The very nature of scripting support requires a fair amount of customization on your part. While it doesn’t seem terribly likely, it is absolutely possible that the glue for an off-the-shelf solution would outweigh the work of creating a new solution for a particular problem domain.
With that in mind, we’ll start by examining a very popular open source scripting language called Lua. It’s light weight, highly portable, and is used in many games, both commercial and otherwise. We may then take a look at some other off-the-shelf solutions, and include them in our study, for completeness’ sake.
Finally, we’ll take a look at creating our own small domain specific language. We’ll go through the process of defining the requirements of the language, coming up the syntax and semantics, and implementing it as an extension to Bayts. Unlike Lua, this will not be a general purpose language. We will be including features we need to define steering behaviors — and nothing else.
This exercise is not intended as a competition, and there will be no winner or loser. Each of the items we’ll be covering has its advantages and uses. Which one is right depends on your particular situation. Different jobs require different tools. Hopefully by the time we’re done, we’ll be better able to figure out when to reach for the Ball Pein, and when to reach for the Cross Pein.