PDA

View Full Version : In Game Scripting



Sean Doherty
11-05-2006, 11:38 AM
I'm looking to implement some kind of in game scripting for events and actions. I've been reading a little bit about action scripts from Jim Adams book and it looks like a viable way to go. Can anyone point me in the right direction? Is there any standard scripting languages out there?

mot
11-05-2006, 11:49 AM
I'm not sure there is a standard language for this but from what I've read so far, other people use Python, Lua, Javascript, the "Small" language, C/C++ compiled into bytecode (Quake3), Unreal script etc.

I just use Java for everything.

Dan MacDonald
11-05-2006, 03:52 PM
LUA is really easy to embed, and expose C++ functions to script and visa versa. Also it only adds about 75k to your release executable.

Philippe
11-05-2006, 04:55 PM
wow, that's a really good selling point for LUA!
I've had to extensively use Python for a recent client project and would like to include it as a scripting language in future games, but so far I know nothing about the process. Can anyone comment on how it compares to LUA, especially in terms of executable size?

edit: I googled: http://lua-users.org/wiki/LuaVersusPython

oNyx
11-06-2006, 12:13 AM
LUA is a very popular scripting language, which was also used in a bunch of AAA games.

Well, you should mention your "host" language. Pros and cons and also performance can differ alot. LUA for example isnt really all that appealing if Java is your host. There are way better options in java land.

I for one script everything in the Java language. I have a framework* (written in Java), which handles caching and offers the whole boiler plate code. The complete game is scripted and the "module" can be reloaded at any time. The loaders are pluggable and theoretically I could support about any scripting language out there (there is one for Python for example). But I only use Java, because I can use Janino (an ultra fast on-the-fly compiler) there and because I can compile it at the end, which means that I dont need to ship an interpreter (say beanshell) or the compiler (say janino) and of course I also get the full speed (like I already get with janino).

Its really amazing. I can interact with everything as usual, the speed is C++ like and turn-over wise its like writing html/js (thanks to media caching) - even on my slow 500mhz machine. Something like that would be sorta impossible with C/C++. Well, it could be done, but it would take a decade or so and one would need mad skills, which I certainly lack. ;)

Well, my approach scales somewhat bad, but its perfectly fine for prototype to (usual) shareware-sized games. Platformer, puzzle/match3, breakout, shoot em up... no big deal.

[* available on google code this xmas]

Fost
11-06-2006, 06:32 AM
We've used lua on Mr. Robot and it has done what it has said on the tin. However, there are more general issues surrounding scripting that have caused us enormous problems - predominantly the issue of debugging. This may be possible to fix though (and already is in the case of c#).

Mark wrote some thoughts on the subject here:

http://www.moonpod.com/board/viewtopic.php?p=14759#14759
(scroll down to 'the dark side of scripting'), that may be worth reading - whilst it probably won't help your decision much, it might illustrate some of the pitfalls to watch out for.

luggage
11-06-2006, 06:42 AM
There's another called Angelscript which I found easier to use than Lua. In order of preference...

Angelscript
Lua
Python

oNyx
11-06-2006, 09:40 AM
[referring to Mark's post]

>Scripting languages [...] are typeless.

Not necessarily and I'm not really a fan of typeless languages. Exchanging a few minutes of typing for hours of hair pulling frustration isnt really a good trade imo.

>So anything complicated, time critical or hardware specific cannot and should not be
>done in a script.

Depends... well, I'm cheating anyways. So my script becomes native code at the end (code->bytecode->machinecode). You could argue that what I'm doing isnt really scripting, but "scripting language" is a very fuzzy term (see wikipedia). My (fuzzy) definition is that there shouldnt be a noticable compile step, because thats what scripting looks like.

Jesse Aldridge
11-06-2006, 10:18 AM
I made my own simplified XML parser. I looked at some of the available scripting languages, but they all seemed like a bit more trouble than they were worth. XML is easy to implement (one of the design goals was that an average programmer would be able to create a parser in a week) and pretty flexible.



I for one script everything in the Java language. I have a framework* (written in Java), which handles caching and offers the whole boiler plate code. The complete game is scripted and the "module" can be reloaded at any time. The loaders are pluggable and theoretically I could support about any scripting language out there (there is one for Python for example). But I only use Java, because I can use Janino (an ultra fast on-the-fly compiler) there and because I can compile it at the end, which means that I dont need to ship an interpreter (say beanshell) or the compiler (say janino) and of course I also get the full speed (like I already get with janino).
...
[* available on google code this xmas]

I'm not sure I understand this 100%, but it sounds pretty cool. I'm looking forward to xmas :)

Slayerizer
11-06-2006, 11:53 AM
There's another called Angelscript which I found easier to use than Lua. In order of preference...

Angelscript
Lua
Python

my vote is also for AngelScript...

oNyx
11-06-2006, 02:57 PM
[...]
I'm not sure I understand this 100%, but it sounds pretty cool. I'm looking forward to xmas :)

Its indeed pretty cool. Couldnt be arsed to explain it more in-depth, because I explained that 2 times already and both times my post got lost in some interweb fluctuation.

Right now there are still a few essential bits and documentation missing. After that it should be in a usable gotcha free state. Well, its the 4th* reincarnation of the framework... so its about time to get everything just right.

[* 1st one was rather simple java2d/javasound, 2nd was a team rewrite with opengl/openal, 3rd was massive refactoring/downsizing and useful additions and the current one repeats the steps of #3 basically... plus making it work with webstart, which also means that you can use it for something else than prototyping.]

Dan MacDonald
11-06-2006, 09:26 PM
We've used lua on Mr. Robot and it has done what it has said on the tin. However, there are more general issues surrounding scripting that have caused us enormous problems - predominantly the issue of debugging. This may be possible to fix though (and already is in the case of c#).

Mark wrote some thoughts on the subject here:

http://www.moonpod.com/board/viewtopic.php?p=14759#14759
(scroll down to 'the dark side of scripting'), that may be worth reading - whilst it probably won't help your decision much, it might illustrate some of the pitfalls to watch out for.

I just used it for event handlers, or trigger responses. In my case I just exposed a bunch of C functions to lua that I called. Sort of like a LUA API for my game. All my lua functions were just calling C Functions that I had exported. The most logic I actually put in lua was an if statment or maybe a local variable. I never really had any problems debugging since one of the nice features of having lua embedded in your application is that when a lua function calls a C function it will actually break on that function in the debugger, so you can step though it normally.

amaranth
11-06-2006, 11:35 PM
I used Ruby with Aveyond. It was pretty easy to learn.

Sharkbait
11-07-2006, 01:02 AM
my vote is also for AngelScript...

Another big fan here. Angelscript is strongly typed and is very much like C# and Java. The latest version now supports classes, inheritance, interfaces and dynamic casting.

Also, integration of native classes and functions into the language is a snap, and writing wrapper functions as required in Lua is virtually never required. AS is cross-platform by the way.

Bad Sector
11-07-2006, 01:14 AM
Like everything else i'm coding, i've also coded my own scripting languages. In fact, creating languages is one of those parts of programming i really like doing, so i have a bunch of them and writing parsers, compilers and virtual machines are like second nature to me - i do it without thinking much :-).


My latest stuff is UndeadScript, which can be seen here (http://forums.indiegamer.com/showthread.php?t=8678) (with the bashing it got :-) and i've already used a premature version of it in Nikwi (http://www.slashstone.com/more/nikwi). It's C-like, strong typed and lovable.

But until a public version (the premature one is very premature :-P) is out, i recommend AngelScript. I can't stand LUA's syntax... and i dislike Python's habit to force scope on indentation.