Skip to main content
gamedev.net
🔒 Locked

[java] Scripting languages for Java

Started by KurtCPP Sep 13, 2006 at 1:22 AM 11 replies 2.5k views
Original Post
KurtCPP
KurtCPP
Hi everyone, we are currently trying to make a RPG in Java and I'd like to know whether scripting languages and engines exist for Java. If we were to use C++ (what I would prefer...), we could simply use Lua but I don't even have a clue as how to integrate Lua into a Java game. Could someone point me to the right URL's please? Thanks a lot in advance. PS. by the way, I'm already asking for scripting tools but in fact, I may not really be able to use them. Do you also know some good tutorials for scripting events and scenarii for RPG please? Cheers [Edited by - KurtCPP on September 18, 2006 1:09:58 AM]
Prog, Games & Rock'n'Roll :I don't like the Prog but the Prog likes me.
Ph0enlx
Ph0enlx
Well after searching on google for "java scripting language" i got more then enough results.

I suggest you try that first :)

Good luck
Kambiz
Kambiz
Java 6 supports scripting languages:
http://www.onjava.com/pub/a/onjava/2006/04/26/mustang-meets-rhino-java-se-6-scripting.html
ScriptEngineManager manager            = new ScriptEngineManager();        ScriptEngine engine            = manager.getEngineByName("js");        engine.put("age", 21);        engine.eval(            "if (age >= 18){ " +                        "    print('Old enough to vote!'); " +                        "} else {" +                        "    print ('Back to school!');" +                        "}");//> Old enough to vote!
CaptainJester
CaptainJester
Quote:
Original post by KurtCPP
Hi everyone,
we are currently trying to make a RPG in Java (yuuuck!!!)


Come into the Java forum and bash the language we all like to use, and then you ask for help?

You don't always need a scripting language. You could just use XML. Java has a built in library to easily parse XML files.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
Raghar
Raghar
Java has zero recompiltation time, so what for do you need scripting languages? Use Java.
Hard Rock
Hard Rock
Theres the afforemention Lua java port, theres also JRuby ( http://jruby.sourceforge.net/ ) which just got backing by sun.. Jython( http://www.jython.org/ ) and I'm sure there are many others.
Hard Rockhttp://www.starsdev.com
Bimble Bob
Bimble Bob
Quote:
we are currently trying to make a RPG in Java (yuuuck!!!)


Whats the difference with making it in C++ or another language?

Anyway if you're feeling really adventurous you could consider making your own language. But really as someone said before you may as well use Java seeing as it will be able to communicate well with the rest of your game and it has barley any compile times.
It's not a bug... it's a feature!
Lucidquiet
Lucidquiet
Some one already mentioned jython, but there is also jscheme.

Who's forcing you to use java -- if you love C++ so much?

L-
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net
Aldacron
Aldacron
Rhino is Mozilla's Java implementation of &#106avascript. It's performant, familiar to a lot of people, easy to integrate into a Java app, and used in quite a few applications. IIRC, it will ship with Java 6 as the default implementation of the new scripting API.

pnuts is reported to be the most performant scripting language for Java. It's developed by a Sun engineer in Japan. It gives several options for executing scripts. Scripts can be compiled to Java class files for even better performance. The biggest drawback is that there aren't a lot of resources at all, but for anyone even semi-intelligent that shouldn't be a hurdle. It's not a difficult language to learn and is easy to integrate into an app.

I'm surprised no one has mention BeanShell. I don't believe it has been updated in a long while, and it has some performance issues since the implementation is designed around reflection. But it is used in several projects and has been around for a long time.

IMO, the need for a scripting language in a Java app is something that should be evaluated carefully. In the C++ world, scripting is the only option for dynamic development. In the Java world, that is not the case.

If I were developing an RPG in Java, I doubt that I would even consider a scripting language. A much better option, as I see it, is just to use Java instead. Using Java's class loading mechanism and dynamic instantiation, it's possible to set up a framework that loads classes at runtime. A basic implementation that loads classes off of the class path is dead easy to implement (see my ClassUtils.java for an example). More advanced features, such as loading only from a specific subdirectory or from any directory in the file system, can be implemented with a custom class loader. In both cases, you can require that the system only instantiate classes which implement a certain interface, or extend a specific class, and you can implement "hot swapping" so that classes can be replaced at runtime. With a custom class loader, you can get even more advanced and implement strict security requirements for 'script' classes (such as restricting them from loading resources from anywhere except a specific directory). For now, using such an approach requires the classes to be compiled before they can be used, but Java 6 will ship with a compiler API that will allow you to compile Java source files at runtime. Then, using Java to script really will be no different than using another scripting language.

Deciding which route to take depends largely on project requirements. For example, if you intend to actively support a modding community for your game then using a scripting language might be a better option -- preferably one which your users are most likely to be familiar with or able to pick up easily (such as the Rhino &#106avascript implementation). &#79;n the other hand, when modding is something you intend to leave to the hardcore players, if you allow it at all, and you want to use scripting primarily for internal development, you may be better off using Java instead. Whatever you decide, just realize that Java itself is a dynamic language and scripting languages are not the &#111;nly choice for scripting.<br><br>If you want to investigate class loading, hot swapping, and other techniques that can help you with building a dynamic class loading framework, the book <a href="http://www.amazon.com/gp/redirect.html?link_code=ur2&tag=gamedevmike-20&camp=1789&creative=9325&location=%2FComponent-Development-Platform-Stuart-Halloway%2Fdp%2F0201753065%2Fsr%3D1-1%2Fqid%3D1158211159%2Fref%3Dsr_1_1%3Fie%3DUTF8%26s%3Dbooks">Component Development for the Java Platform</a> is a great place to start. It's 5 years old, but still relevant for the topic. Even if you don't use such a system for scripting, it's very useful as a plugin framework.
KurtCPP
KurtCPP
Hi everyone,


First thanks for answering, second sorry for the trouble...
I won't be able to answer each question you asked me in your posts, but I'll just say that we gotta use Java because the guys of my club are frightened of C++ and since they've just learned Java at school, they think it's better than the remainder, but this is not the point of this thread.



I think LuaJava could be a good solution but I've never been a scripting laguages guru. What I want is to make a very flexible game because we have to work with the guys of another club and they really would like us to do something that could be used as a game editor. You may think that they'd better download something like RPGMaker, but *our* own purpose (I mean for the guys of my club) is to code something by ourselves.



Regarding XML, this is already what I use for the base configurations (maps, characters and so on) but I'm not sure I could describe scenarii and game events with this. What do you think about this?



One more thing : do you know what engine we'd better use for our 2D graphics? I'd like to use something like LWJGL (it could be great if the game evolves and gets 3D environments) but I don't know what it's really worth.


Thanks in advance for your help.
Cheers.
Prog, Games & Rock'n'Roll :I don't like the Prog but the Prog likes me.
Joakim_ar
Joakim_ar
My advise is only to use XML if you need the data to be editable by people and you don't want to provide a dedicated editor.

As for maps, XML is probably not a terribly good choice - storing it in XML won't make it easy to edit it by hand if the map is remotely big. It's also going to take up more disk space (I guess you can ignore that) and it's going to be slower to load and store than if you make your own format. Characters are probably a good candidate for XML as you might want to edit it by hand and chances are the files won't be too cluttered. As for scripting, you're eventually going to end up implementing control structures and flags/variables on top of XML... I leave the conclusion up to you ;-)
KurtCPP
KurtCPP
Hi,


Thanks for your answer. But I have to say that we are almost forced to provide a dedicated editor. Regarding the maps, they're not really described by XML (don't worry, I'm not such a bad coder!), but their content is (objects, passages, etc.). Is this a bad idea too?




Regarding the idea you gave me about flags and control structures, could you please give me an example of this or useful URL's. This concepts looks quite interesting but I can't really get the way one could implement it.




Thanks in advance.


Cheers.
Prog, Games & Rock'n'Roll :I don't like the Prog but the Prog likes me.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.