Scripting languages (again!)

I’m expanding Rescue Squad and one of the things I’d like to have is more interesting and varied levels which change on the fly (things going wrong, changing objectives, etc.). The obvious method would be some kind of simple scripting support, so I’m looking into which existing languages to use.

Searching through the forums, the main choices seem to be Beanshell, Groovy, Pnuts and Jython. Beanshell would be an obvious choice, as I wouldn’t have to waste time learning a new language and the amount of work required to intergrate it and expose an API to it seems minimal. However every reference to it in the forum search seems to be people complaining about it’s poor performance, which kind of puts me off somewhat.

Ideally I’d like a “simpler” language to script in (ie. less boilerplate code, less strict typing, etc.), so Jython would seem to be a good option, but I suspect that would require quite a bit of more work to intergrate and manully expose a suitable API to the scripting language.

Since I’d like to stick to 1.4, anything that requires the new scripting stuff in the JRE is probably not suitable either. Anyone any recommendations before I just randomly pick one?

Well, i guess that all ur script calls are going to be driven by some events, and will not occur always in main loop iterations, i guess that beanshell would do the job-it did for me anyways…

Bump, there must be some people with ideas about this. Wheres the obligitory post by oNyx that beanshell is slower than a dead snail? :wink:

Currently, I’m leaning towards Jython, since the Python language is (IMHO) quite neat and has minimal boilerplate required for a basic script. However I still havn’t actually started trying to intergrate it and get it hooked up to the rest of the game proper.

Heh. Well, Beanshell is… ehm… not so cool, if you want to use something overly fancy like… loops. :wink:

The big downside of Jython is the indexing, which happens on the first run. This can take a couple of minutes on slow machines. Quite the show stopper imo.

I think I would either give Pnuts or Groovy a whirl.

Janino would be also an option. The the scripts can be compiled on level load (don’t worry… it’s fast) and then evaluated (=executed) as often as you like at full speed.

Well, if you really want to get rid of strong typing you could also try Rhino (JS).

Uh, indexing? I’ve not heard anything about that. Got a link?

Well, maybe it doesn’t do that anymore. Feel free to give it a try.

Ah… found it:
http://wiki.python.org/jython/PackageScanning

Hmm… interesting, I’ll have to keep an eye out for that.

Although the worst case is that if it’s too slow to be acceptable I could always disable package scanning and make sure to reference everything by absolute class name. I was already planning on appending a set of standard imports to every script when loaded, so this would just be an extension of that.

What about Lua? It’s a programming/scripting language which is used by quite a few games and applications.

I haven’t used BeanShell in a game but I can say that it is not slow when the API’s you are accessing are real java classes (not beanshell code) and these parts of the code will run as fast as any java code. BeanShell code itself is slow because it is executed through reflection (java.lang.reflect).

Since the rendering code in a game usually takes the most time, and you’re only using BeanShell to make maps, it probably won’t be an issue.

One thing that’s annoying about BeanShell is that it’s not exactly like Java code and it’s annoying when things don’t work as they should, such as nested classes and anonymous classes which are buggy. I’m sure that all of the scripting languages have things like this though, and none have been arounf as long as BeanShell that I know of. I think it’s a real pity that Sun haven’t picked it up - it’s so obvious that we should have an exact java-syntax scripting language…

What would be the difference between the java-language and an exact java-syntax scripting language?

A script doesn’t need Java recompilation whereas Java code does. Plus it can make for easier development of simple behaviour, such as RPG scripts.

  1. higher turn-over rates (especially on slow machines)
  2. user can script without the hefty tools.jar bloat (~200kb vs ~6mb)
  3. scripts can be compiled the usual way at the end for more speed and a smaller download
  4. there is no new language to learn

For me it’s 1+3 and a variation of 4 - I simply like Java (and I already know enough languages). I prefer strong typed languages and C-like syntax. And I really love Java’s awesome documentation.

The number of keystrokes is the least interesting aspect of programming languages. Standardized code conventions for example have a far bigger impact on productivity.

When you’re writing 100 unique combat variations for an RPG (you need a different combat snippet for each unique special effect and strange combination of super-abilities, like “unblockable”) - obviously only overriding small parts of the combat each time! - and you have a couple of level-designers writing hundreds of different effects in each level … well, you can easily save months of time just in not having to keep recompiling each script to see it work.

There’s also the fact that scripts can be altered on the fly whilst hte engine is running and you’ve already setup a particular situation (e.g. run a particular level for 20 minutes to get to a situation you want to tweak). Eclipse can, obviously, do some hot-swapping of code, but tis not perfect, breaks on quite a lot of things, and requires you to be happy editing java source directly. Which means knowing the package structures etc.

Everyone forgot Rino? LOL http://www.mozilla.org/rhino/ good thing about this option is that there are lots of skilled java script coders allready. Speed does seap fairly good.

We are using BSH though for 2 reasons. We dont run the BSH code often in the game so we can get away with slower. We create listner classes to various events to trigger things. As far as I know no other scripting language can do that.

Looking forward to the next version that promisses to pre compile the script to byte code.

–Travis

If you only need a few different commands, you might try just writing your own simple scripting language. You might even do a “one line per command” language to avoid writing a real parser.

With your own language, you can precompile the scripts before they’re needed.

Even if this is an old thread, I feel I have to add my experience.

I used beanshell (with loops) to make my game: http://gunslinger-game.mine.nu/
It works great. Never any trouble.

But the game does relay on compiled code mostly. On every map there are from 2 to 8 statemachines running at various intervals (they have to tell when they want to run next before they exit).
This can do things like: “check if this has happend, advance the state and give the player a message”. Typically from a few times each second to a few seconds between each run.

Also, some GameObject have event handlers that triggers on certain events. Like “onDeath”, “onTouch” etc These are not run that often.
Also, dialogs have conditions for certain lines and actions for lines.

This isn’t an awful lot but sometimes I do pretty awesome things with it (the best is when an npc ends a dialog by shooting himself in the head (and is then beeing replaced by a corpse), or when you break open an artillery cannon to extract the grenade and rig it as a bomb that you can acutally use for a weapon). ;D

Of course, all scripting languages will work for this. But beanshell is almost exactly like java. Very easy to integrate.