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.

Comments (6)

  1. christian b says:

    interesting and a simplistic approach to language implementation – like it.

    on the why you would embed a scripting language into the game, I guess you answered that yourself. from the simple example you gave, the scripting language can be used to raise the bar of abstraction. a concept like "open door" or "spawn entity" simply does not exist in c# (or any close language for that matter). consequently, level designers (or whoever) is able to communicate in a domain specific language which may make them more productive (abstraction for commonalities, etc.)

    another thought on the why would be … learn about implementing a language

    make your environment more adaptable

    expose internals without the need to recompile

    and maybe some more



  2. brandf says:

    Thanks for the comment Christain.  I think you bring up some good uses.  Right now I'm grasping onto the 'learn about implementing a language' reason, but I have a feeling that I'll find more and more uses for this.

  3. christian b says:

    Yepp, I wanted to do that myself however haven't really found the time to do so. There is books like …

    Language Implementation Patterns and AI Application Programming that feature sections on that topic also you might want to check out AntLr – a parser generator framework which can be targeted to .NET.

  4. brandf says:

    Thanks christian.  I haven't had a lot of time to work on this lately, but when I get back to it I'll check out that book.

    I'm not crazy about the parser generator idea.  I've used them in the past (flex/bison) and I'm not convinced they save you any time.  At least not for a lisp like language that's quite easy to parse.

  5. Mew says:

    MMOGSTOP.com is the leading provider of WoWGold, FFXI Gil, RS Gold,EverQuest Platinum, and Warhammer online gold.MMOG STOP delivers fast, safe and always guaranteed.

  6. Mew says:

    MMOGSTOP.com is the leading provider of WoWGold, FFXI Gil, RS Gold,EverQuest Platinum, and Warhammer online gold.MMOG STOP delivers fast, safe and always guaranteed.

Skip to main content