Hi core team and eager users,
I thought about the idea of the support of a scripting language in jME3 like there is in so many games out there. Mostly you see python or lua getting used for level description/loading or AI management etc. because it allows for (even easier) prototyping than with Java. Also it helps in abstracting game logic and keeping the core code of the game more clean. Furthermore jME3 would have the typical console to inspect and change data at runtime. To list all the benefits would be a bit too much at this point.
My preference is Python, definitely. And there exists an excellent Python-To-Java-Compiler project called Jython (http://www.jython.org) that produces (also at runtime, as I understood) byte-code .class-files and also supplies multi-threading, GC and all the good Java stuff
I just wanted to see whether there are concerns or more ideas from every side and whether this would be a real benefit or just a waste of time. At one point in my game I would certainly would want to have such a system and if there is positive feedback I could try to implement a first draft of it.
@normen:
Hmm, ok thanks for your opinion.
I looked it up and there really exists a javax.script package (that uses Jython for its python backend BTW). Good to know. I guess that eventually I will write some generic (i.e. using whatever scripting language backend) ScriptAppState which also provides a console to the game. But we’ll see.
@EmpirePhoenix:
Yeah, how are class instances handled? I would like to pass object instances, like models, into the global namespace of the script (say: ‘script.put(model,“modelName”)’) and write into the console things like “modelName.rotate()”. This probably works with Jython. Do know about such things with Java?
Well while I can understand when some want to have that, i myself are happy to never have to use lua again. (As soon as it is a little bit more complex you spend like 90% of the time debugging typos)
Hehe,
yes I know lua myself from former times and am also happy to have completely forgotten about it. The advantage with python is the amount of good IDEs it has, the rather good error messages and the very fluent integration into Java with Jython.
No, java has support for scripting languages so you can use that. i personally dont see the benefit in usng a scripting language when you have a clean language like Java as basis anyway.
ACtually you could use java as a scripting languag, thanks to the javac class you can compile soucecode at run time and load it
@Dodikles :
I totally agreed with you cause I really love Python and it will be good in game!
About the thing you said :
I would like to pass object instances, like models, into the global namespace of the script (say: ‘script.put(model,”modelName”)’) and write into the console things like “modelName.rotate()”.
I think you must have an entity system which an entity include
- model (mesh data + animation )
- attribute ( pos/rot/scale , physicsModel, visible , shaddowMode , renderable , …)
- AI model (code , thinkable , shootable , runable , …) <== which Python can handle …
Yeah sure,
basically Jython (and I guess the other scripting languages, too) already provides that. If I push objects into the script namespace I can access them naturally.
So if my Java class looks like
[java]public class TestClass
{
int x;
void doSomething();
}[/java]
And I have an instance of it which I push into the script environment, like this:
[java]TestClass lol = new TestClass();
script.put(lol,“testlol”);[/java]
I could afterwards load a script file or write into my console (at runtime, that is!) things like:
[java]# sample python code
testlol.x = 5
testlol.doSomething()[/java]
and alter them at runtime. You wouldn’t need an entity system or something. The script gives naturally access to Java objects with their full attributes, methods and so on! Great, as I think You could access the renderer, assetLoader etc. And you could take whatever scripting language you like because of the javax.script package.
Yes , I know we can do that with Jython like put more attribute in the object after creating it.
But why we need an entity system is we have to build an “Editor” for our game which place something somewhere and we can modify or jump in to play anytime anywhere. So It need “pure-data” things not the “script-added-data” things
I don’t want to distract but if you look at the way “Unity” engine work, it have an entity system to make various object type (which is good and bad in other way) but… It can handle AI by a very impressive method via Script …
I think Python can really do that in JME
I think you want to look at something like this in addition for your “Jython-Scripting engine” implemention …
It’s a Game Entity System written in java
and maybe a “ScriptPiece” or “ScriptControl” like “Runable.py” or “NPC.py”
can also be a component of the entity just like “Pos/Rot/Scale” or “RenderInfo”
They 're both entity’s component and can be add or remove if nessecery!!!
… (if you know what I mean )
http://code.google.com/p/spartanframework/
and did you ever think about Clojuse for Scripting ???
Ok,
I understand what you mean (and it has its benefits) but you already go a bit further with your entity system than I intended to go.
But yes, think of AI code that sits somewhere in a .py-file and you swap AI algorithms on the fly by assigning your entity a new AI .py-file. Or edit your AI script in a text editor and reload it while the application is running at the same time. This scheme applies to a lot of use cases where you want to randomly test/modify data/algos or swap logic on the fly.
If you use the standard java scripting extensions then you can plug-in all kinds of stuff (as you’ve discovered). Groovy would be my personal favorite but that’s just because it’s very java-like but with lots of dynamic goodies.
At any rate, someone has put together a JSR 223 compatible ‘scripting environment’ called mutant which lets you freely switch between different scripting languages right in the same script.
I don’t know how mature it is but it looked pretty cool when I saw it pop up a while back: Mutant.
@pspeed, I agree IMO groovy would be the way to go for interfacing a scripting language and java.
But honestly, I think the same as Normen. I don’t really see a benefit of a scripting language for a java engine.
@Dodikles if you do eventually decide to start a small project for this stuff, you should get in touch with @antonyudin first since I recall he already had some working setup of his own on this end.
Yes, Groovy will be easily intergrated in any Java project in notime… I’m just curious about Python cause there is some thing “game-related with” Python out there…
This is my small prog for testing some trigger in JME with Groovy in JMP. I 'll be glad to tell you guy if I 've done some thing more complex with Groovy Script for trigger or console…
At the moment I play around with 2 fun tets:
- mapping all the entity (spartial with its own attribute) by name in the scope of script
- let them move or interact with each other or let them play animation by trigger (the improved “trigger” code from monkey zone project)
Cool,
get on with it! Let’s see what will come out of your effort.
I have my last exam on Thursday and will start to look closer at the idea afterwards. How about you also try to incorporate some kind of in-game console? Nifty has an example of such a gui-console somewhere. This would be very cool and would enhance JME in my opinion
I really want to wait for Nifty got in to its stable status (a few more weeks) which give us more strength to do some thing further . I will add a link of my trigger + script test in this thread soon
Scripting is fun, you can extend anything … even something like Vector3f so that it’s “toString()” method sends data by HTTP as a side effect … and best of all; you can serialize that instance and it’ll unpack correctly on the other side
Hello.
I have been using scripting with JME3 for very long time.
Java has, I would say, a perfect mechanism to plug different scripting environments (JSR-223).
You can use at least those languages: JavaScript, Python, Ruby, Groovy. The list of supported languages includes more than 20 languages.
Also I’m using the same mechanism to make my console work with commands. Instead of parsing commands, I just call “eval” for the specific language. I had to implement my own tab-completion, because there is no such functionality in JSR-223.
The basic idea is this. A have a command line argument “–execute file” that tells the Application class to execute this file as script as the last thing in simpleInitApp. Before executing this script, I “expose” certain objects to the script. For example, I make an instance of JME application available as a global variable “client” for the script. So the script can basically call client.getRoot().attachChild() and actually do anything. It can instantiate Java classes and have full access to them.
One thing that is missing is that you cannot “include” javaScript (I’m using JS) files inside other files. So I implemented a method called “execute” in the application class, so that the script can call ‘client.execute(“another.js”);’. That lets me have a set of libraries and make the actual script that load the scenes and controls interaction between scene objects pretty simple.
I also implemented a bridge between one motion capture system called “Organic Motion” and made it accessible in scripting language. So the script decides to which object the transformation matrices from the motion capture system are applied.
If somebody needs the code for that or has any questions, I’m eager to share and answer!.
Thanks.
@antonyudin :
It’s awesome
Please share your code … It’s cool to see some Pythons that ride by Monkeys !!!
And do you have something interesting about “Motion capture”… I just have a quick look in “Organic Motion” . It’s a marker-less solution for Mocap , right? Do you have something “Mocap-related” to share I might ask?
Thanks