Saturday, October 08, 2011

Embeddable Scripting Languages for Games

I've thought about using Lua for game scripting (easier, more flexible, less freaky for others than our GameForth). Lua is used in lots of games, such as World of Warcraft, Baulder's Gate, Angry Birds, Civilization V, Escape from Monkey Island, Far Cry, Lego Universe, Homeworld 2, Plants vs. Zombies, The Sims 2: Nightlight, SimCity 4 ... [1]

Anyway, assuming a need for one of my games, I saw another embeddable scripting language mentioned in a Linux magazine called Squirrel.

It seems to have the following advantages that are good from my perspective:
  • More C-like syntax than Lua (although Lua syntax is not too bad - a bit BASIC or Pascal like)
  • Classes supported by default (classes can be implemented relatively easily in Lua with tables)

Squirrel has been used for Code::Blocks, Final Fantasy Crystal Chronicles: My Life as a King, Left 4 Dead 2 and Portal 2. [2]

Anyway a couple of links for Squirrel:

 function factorial(x)
{
if (x == 0) {
return 1;
}
else {
return x * factorial(x-1);
}
}


A couple of links for Lua

  function factorial(n)
if n == 0 then
return 1
else
return n * factorial(n - 1)
end
end


A comparison:
http://wiki.squirrel-lang.org/default.aspx/SquirrelWiki/LuaComparedToSquirrel.html

Also this:

"The Python/C API manual is longer than the whole Lua manual (including the Lua/C API).

Another reason for Lua is the built-in support for coroutines (co-operative multitasking within the one OS thread). It allows one to have like 1000's of seemingly individual scripts running very fast alongside each other. Like one script per monster/weapon or so."

from http://stackoverflow.com/questions/87889/game-engine-scripting-languages


Squirrel has cooperative threads(co-routines) ... according to http://squirrel-lang.org/

Other Choices

Another one is Angelscript (discussion here http://www.gamedev.net/topic/505855-lua-squirrel-or-angelscript/ )

From www.angelcode.com:

"Efforts have been made to let it call standard C functions and C++ methods with no need for proxy functions. The application simply registers the functions, objects, and methods that the scripts should be able to work with and nothing more has to be done with your code. The same functions used by the application internally can also be used by the scripting engine, which eliminates the need to duplicate functionality."

Angelcode also has co-routines - http://www.angelcode.com/angelscript/sdk/docs/manual/doc_samples_corout.html

Obviously things like Python (and stackless-Python) are technically possible to be used as embedded languages, and some people do use them in this fashion - but for games they've been seen as too heavy weight.


Regards,
Rob


[1] http://en.wikipedia.org/wiki/Category:Lua-scripted_video_games
[2] http://en.wikipedia.org/wiki/Squirrel_(programming_language)
Newer›  ‹Older