A good scripting language for java games

I know that ease of use and performance are important elements when choosing a language for implementing logic and artificial intelligent in games. There exist some nice feature rich scripting languages that are useful when focusing on these requirements. However, integrating a strong scripting language with full access to the java API into a game engine raises a few important questions. If the intention is to allow players to modify and adjust the scripts a strong scripting language can be misused and therefore be a potential security risk. Additional, a strong scripting language might use features of the java language like e.g. deprecated methods that can undermine stability of the game over time.

How do you guys deal with this issue? Or do you actually think it is worth taking into consideration when choosing a scripting language?

Yes but make that work in-game…

We need a way to edit object behavior in-game/game editor while the game is running.
This has become the standard for level design, editing and development.

This can be done with Java but since Eclipse does it but it does require a compile step. With a script it is REAL easy to make work in-game (i.e. one reload script button or even a textarea for little snippet changes in the game editor GUI)

Also, the level designer doesn’t have to have a Java dev suite installed and set-up (read configured with proper project paths etc). They just need the game itself. (and embedded editor like we do it :-))

I use applet alike entry points (init, tick, render, destroy) and just script everything from that point. Its a full class which in turn can instanciate other (fully scripted) classes etc. If janino spits out some really weird error (happens sometimes), I just compile it the usual way and check what went wrong.

This approach works perfectly for prototypes or small games (and basically its the same as your approach, but the difference is that I get full speed and that I can do a usual compile at the end).

@benjamin

Well, there are different solutions for different problems. I’m for example not interested in letting other people fiddle around with my scripts (there wont be any at the end anyways). So its perfectly fine to ignore all possible security issues.

If you want that players can script stuff (and exchange scripts), you have to pick some scripting language with access control or restrict access through other means.

We did agent/ai scripting recently and I can say it was definitely not as easy as expected.

if you allow users to wirte AI scripts, one main challange is that they don’t interfere with the running system. The easiest hack is to do huge computations, which will prevent the other from thinking, acting and further will break the rendering and animtion if the system is single threaded. Therefore we run every single agent in an own thread, which leads synchronzations issues with their perception and action tasks…

for most games however this won’t ne needed, because the scripting is only used to simplify the development process, ‘securing’ isn’t needed usually.

The hotswappable code in eclipse is not really suited for this. When you significantly change your code (add a method, field, etc) the hotswap fails.
And when it is supposed to work, I quite often (twice a day…) get a VM crash after the hotswap.

It’s much more convenient to have something that can be reloaded on the fly, and always works.

Last point would be that in Java (as in all OO languages) the boiler-plate code is quite big. It gets a bit annoying when doing lots of tiny scripts.

My own scripting-language just has some very trival shortcuts, that the parser turns into java-code, which is fed into the compiler inside tools.jar - for me it works out very well, you get 100% performance. And as all scripts are run server-side, I don’t have to distribute tools.jar to everybody.
To get aruond the massive tools.jar filesize, one could use Jikes, which is extremely fast, but AFAIK only does Java up to 1.4.

Thanks for the input. It really helped to broaden my knowledge of how to address the scripting issue.

After trying to use two different scripting languages: Groovy and Pnuts I realize that I was unable to speed up the development process of games. Of course, I am not a guru in these languages and I might improve with time. However, developing in java is not so slow anymore as it used to be. Tools like Eclipse really speed up the development process. Moreover, scripting languages like Groovy and Pnuts is based on the same syntax as java with only minor useful changes for gaming (you might disagree on this though). I am therefore questioning the benefit of using scripting languages in gaming if you have a nice game library/engine to support the development. Of course scripting languages are often considered because it is possible to see changes in real-time while developing. With the introduction of JSR 199 into java 1.6 this is now also something that is possible for the java language.

I still have an issue regarding the security and stability that I need to work out. Nevertheless, I will go with the traditional java approach for now.

I could have sworn that I mentioned this before on this thread but I can’t see any evidence of it- Steve Yegge put together an interesting comparison of different JVM scripting languages where he wrote a simple but complete application with them. An interesting read.

At the moment I’m using scripting languages to prototype algorithms.
I’m using Python and Beanshell.
Let me quote myself from another thread I made 4am this morning.

I’ve discovered the wonderful world of scripting. :slight_smile:

[quote]I’ve done scripting before, however it isn’t the same when the scripting language you are working in is dynamic and ties into your normal programming routine.

http://www.beanshell.org/

I’m learning how to use this, so far it’s amazing as to what it can do.
Dynamic typing is awesome(I remember saying this before in a discussion about Ruby).
No more need for things such as Vector2f. Instead “v = Vector2(0.0, 0.0)” or “v = Vector2(0.0f, 0.0f)”.
Closures are supported.
Classpath modifications, so I can import my assignments and dynamically modify things from within my code to test it before it gets finalised.
I’m wondering if this can output into bytecode for re-use.

I wonder if there is anything like this for C++. Interpreted C++ would be awesome to sort out bugs and really mess around with things.

Soon I will be loading in OpenGL libs (LWJGL) into my scripting to complete my second assignment for Computer Graphics, then write it into C++.
Testing out algorithms on a scripting language saves heaps of time.
I can’t believe I only realised the usefulness of this just recently, I’ve read and been told millions of times before that scripting can save tremendous amounts of time but I’ve never personally realised it until I got myself a complex problem, scripted it and compared it to production code.

Debugging complex code is hard. Debugging scripted code is easy.
Finalise the algorithm in the scripting stage and throw it into the fire after sorting it out.
It takes very little time to go from A -> B, even if you’re implementing a complex design.
[/quote]

Also it is against the sun license to redistribute tools.jar… just a head up for anyone that is doing it.