On Scripting Languages in Games

Until recently I never really saw the point of embedding a scripting language in your game.  I’m already pretty good with C#, so why would I want to use some other language to write game code?  I don’t' have a staff of level designers that can sorta code either, so what’s the point?  Plus it’s not a trivial amount of work to expose your game systems to scripts…I’d have a hard time justifying it as a productivity enhancement for the scale of games I work on.


So what’s changed?


Nothing really, I just got bored and needed an excuse to write a language.  In retrospect I’m considering it for use as a game scripting system, but I’m not yet convinced it’s a good idea.


The language I wrote is LISP-like although I played around a bit with the syntax.  I chose this style of language for a few reasons:

  1. I don’t know squat about writing languages, and this seemed easy to write.  It was.
  2. It’s a dynamic language, which for a scripting language is a good thing IMO.
  3. I’ve never used LISP before, but I’ve heard good things.  What better way to learn it than to write it?
  4. I like the quoting feature of LISP.  It might come in handy in places where I’ve previously used XML.

It looks a bit like this:

 (if (> time 90)
        (spawn-entity "goomba" `(100 200))
        (send-message self "disable")   

As you can see, lists are formed via whitespace separated tokens surrounded in parenthesis.  The first item in a list should evaluate to a function which is then called with the rest of the items as the arguments.  The syntax takes a bit to get use to, but if you format it sanely it’s not too bad.  And it’s a hell of a lot easier to parse/interpret than a C-like language.


Possible uses in a game could be:

  • Coordinating level-specific behavior such as scripting cutscenes
  • Scripting level-specific entity behavior.  Something like “when the player presses this switch, raise that platform and enable that trigger”.
  • In-game console used for debugging and such.

All stuff that could be done without a full blown scripting language…but that’s not really the point.  Sometimes it’s fun to do something just for the sake of experimentation.  You never know when it’s going to turn into something you hadn’t anticipated.


I’ve got a pretty good suite of unit tests going, but I’m still working on reducing garbage before I post it online.  I’ll save that for another post.