54
\$\begingroup\$

In what cases are what scripting languages better than others?

All answers are appreciated, please provide a description, and describe in what cases the language excels in.

\$\endgroup\$
41
\$\begingroup\$

Lua

It is widely used in the game industry, from independent games (Aquaria) to AAA titles (Civilization V).

The core reason? I would say because it is easy to learn and easy to incorporate into your games. Scripting, in general, isn't difficult. I think the real reason you should go with Lua is because it's proven which results in much more resources out there for you to learn from.

It provides "meta language" features. You can implement object-oriented structures, or pure procedural functions, etc. It has a very simple C interface, and gives the engine developer a lot of flexibility in the language itself.

Artists tend to love Lua too because it's very approachable, with plain and forgiving syntax. If your codebase is C or C++, I would highly recommend it.

It has good runtime performance when compared to other scripting languages like Python. (...and it has full support for closures.)

It has a small memory footprint (approx 150k), it has excellent C/C++ bindings making it easy to add new game specific APIs, it is easy to pick up, it is flexible - i.e Has elements of OO, imperative and functional - none of which are mandatory, it has good buy-in from from mod community from games such as WoW etc.

Squirrel

Squirrel has an interesting history. It was built after a game architect had issues with Lua's unpredictable garbage collection, and crazy everything is null even if it doesn't exist.

Squirrel is the sripting language used in Left 4 Dead 2. The API is very lua-like (Squirrel's author loves Lua's design).

So Squirrel is an awesome language as it's kinda 2nd generation Lua. It took the good ideas and removed the annoying eccentricities.

Same from Lua:

  • coroutines
  • tables and metatables
  • dynamic typed
  • lots more

New to Squirrel:

  • classes
  • arrays
  • regexs instead of Lua's match syntax.
  • C/C++/Java/C# style language instead of Pascal/Delphi style.
  • lots more

Squirrel's primary disadvantage is it's not Lua. Lua is much more widely used. But if that's not an issue Squirrel is an easy win. However, often the language's popularity is useful feature in itself, so the decision is not so clear cut.

V8 Javascript from google

PRO's

  • Quite easy to use
  • Constantly getting better
  • Powerful and flexible
  • Others: As many mentioned , javascript is a common programmer tool. Adding it to my games has opened far more people who feel capable than other languages. It also supports a huge amount of casting and conversion to save on work for the programmer, also makes it really easy to use, works well with STL.

Possible CON's:

  • Documentation can be confusing: Its really not the best.
  • Examples** Often a web of weirdness. Lacking in solid simplicity, it comes across as way higher level than it is.
  • Templates** Sometimes these are hated on, or avoided.
  • SDK Codebase size** Generated code size may be consider bloat.

GameMonkey

This one is used by several teams. It's faster than Lua and better at threading.

Python

This one has been used in several games (e.g. Civilization IV).

It is very easy to teach to non-programmers/designers. It is even easier to pick up for developers since it essentially reads like pseudocode. Being dynamically typed is just one of the aspects that help to get people with little to no prior coding experience up and running fast with the language.

Possible cons:

  • The C bindings for python are much more geared towards extending python with C, than embedding python in C.

JavaScript

This is a possible option as you can download JavaScript engines. There are more JavaScript programmers than any other type of programmer.

SCUMM

This specialized language has been used in several adventure games and it is particularly suited to those games.

mono-script

This allows you to use the Novell implementation of the .NET framework for scripting.

Here's another page about embedding mono in your application.

The Mono framework is faster than most (perhaps all?) of scripting languages out there because it's not interpreted, and because there's a layer between the compiler and the instruction set, it allows you to program in a variety of languages including C# and dialects of Python, Lua and Javascript.

Possible cons:

  • If you're doing console development (including iOS), JITing code is apparently out of the question because you can't mark data pages as executable. The IL it has to be pre-compiled to the target platform.
  • Mono has license restrictions. You need a commercial license if you want to use it in an environment where the end user is not allowed/able to upgrade the Mono runtime.

AngelScript

Some find this one much easier to bind to C++ than Lua.

That being said, I suspect Lua has a few advantages that make it compelling for commercial games developers:

  • It's more mature and widespread than AngelScript
  • Its syntax is easier for non-programmers (AngelScript is very C++-like)
  • It has a smaller footprint than AngelScript (at least as far as I recall)

If you're just writing a hobby project, though, I'd say that AngelScript's at least worth a look.

Scheme

Well, guile specifically.

With guile you can have your own DSL (Domain Specific Language) just for your game. Once you get used to the parentheses and prefix notation, scheme is heaven to work with.

ActionScript

This is a hybrid dynamic/static typed language used to create Flash games, which can be widely distributed on the web. It is fairly well supported with libraries like Flixel, FlashPunk and Box2d.

Roll your own

Yes, writing a compiler and/or interpreter for a scripting language might take a week or two, but in the long run the flexibility will pay of many times. Just don't go to far astray and reinvent brainfuck.


General tips

You should choose a scripting language that has stable and well-supported bindings to your game's primary development language.

If you are writing your game in C or C++, then there are pretty solid bindings available for Python and Lua. If you are writing your game for the .NET platform (using C# or another language), then I highly recommend using either IronPython or IronRuby. Both are complete language implementations that leverage Microsoft's Dynamic Language Runtime (DLR), which provides excellent performance and very tight integration with the .NET Framework. Interoperability between C# and IronPython/IronRuby is pretty smooth these days, especially with the introduction of dynamic callsite binding in C# 4.0.

Choosing one scripting language over another is dependent on your specific requirements. Some of the options you have to choose between could be:

  • Speed of the interpreter - if the feature of scripting is solely used i.e. by developers to script static behaviour, then speed and a fully-fledged and extendable API may be the most important aspect. I had some good experiences with LUA there.
  • Easy to learn, accessibility - for a content-/leveldesigner it may be hard to learn more complex scripting languages (depends on the background) to generate dynamic behaviour. In that case, the use of easy to learn (i.e. commonly used) and well documented languages could be more appropriate here. JavaScript or Python could be a good solution here.
  • Workflow integration - if you have a specific production pipeline with already existing tools, it could be a bad idea to use a language which seems to work best for a given case if the other tools are working with a completely different one. This is especially valid if you have several programmers working on the different tools. In that case, it could be more efficient to use the "not quite fitting" language.

If you have an existing team that will use the scripting language or a lead (level)designer that will use the scripting, then go with whatever their language of choice is. They will be spending their time with it, so they should be catered to.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.