The perfect scripting language

In general I don’t like scripting languages. But you have to admit it’s much faster to iterate changes in a scripting language than C++. Here’s a simplified list of pros and cons:

Pros of C/C++:
Fast execution
Compiler helps you find errors
Full access to the engine.

Pros of Scripting:
Fast iteration
Easy for users to modify


Cons of C++:
Slow iteration
Hard for users to modify

Cons of scripting:
Slow execution
Error prone
Access limited to exposed interfaces

It’s true that any language which can be interpreted can be compiled, and any language which can be compiled can be interpreted. So how’s this for an idea:
Your scripting language is C or C++ (why invent a new language?) which is interpreted and has full access to all your other code. Obviously your script can only call into your engine, and not vice-versa, but this is the only limitation.

Since it’s a script, it is valid and reasonable to hardcode numbers into the script.. You can tweak these numbers and change the script while the game is running to play around with settings.

When you are ready to ship a build, switch your flag to compile rather than interpret the scripts. Or, if you wish user mods, just leave it interpreted.

This is one use of a script system that makes sense to me and I’d fully support in a game project.

Note: there is a library called AngelScript but I’m not sure if it’s capable of doing everything I outlined here. If so, let me know!

2 replies on “The perfect scripting language”

One more con of C++: it’s a notoriously hard language. Not all your game scripters will be good programmers (well, that depends on the game/company of course).

The other alternative is choosing a fast scripting language. E.g. .NET/Mono is pretty fast, so is Lua (combine with LuaJIT), etc. Sure, there’s probably a 2x speed difference if compared to native C++, but at 2x noone cares. In any language you can do stupid things that will make the code 10x slower, so a language that does not let you easily do stupid things is far better.

We do have quite a lot of users that are very beginners at scripting/programming. So what we do is provide C# scripting and JavaScript-like one. JS is still compiled to the same .NET bytecode, and hence runs as fast as C# scripts (if you don’t do stupid things of course), but is a lot easier for beginners to understand and quite often the code is a bit shorter as well.

Oh, and the best way to tweak anything is building a GUI for it! That’s one more pro for a scripting language that exposes some kind of reflection: you can just read all publicly declared variables in the script and build a GUI to tweak them.

[…] I wrote about AngelScript a while back yet never had a reason to put it in the code up until today. This morning I was thinking about how to go about a general effects system for my game and concluded that the only thing flexible enough was either code or script. I specify effect files in XML settings, and those can’t refer to code (easily) so that left me with script. Plus this is really one of those rare times when scripting makes good sense: […]

Leave a Reply

Your email address will not be published. Required fields are marked *