hmm It seems like there is a Module for jython…
This is over my head but from a video I watched about java 7, you can use Python directly (by “injection” it seems) and it’s interpreted directly into java. Java 7 (both the JDK and the JRE) are available for download. They weren’t marked as beta or anything. Maybe you guys should try it?
Sorry if I’m “out of line” here. But I thought you’d like to know. If I’m assuming wrong, disregard this post.
I remember back 3 or 4 months ago I came across jython for the need of a good scripting language for my game but …how much I love python , how many things prevent me use jython …
My only one reason is :
python has very good support and a lot of hook-in and plug-in libraries and already solved a various of prob… However jython can’t seem to provide those good features as expected…
So may be we can lay our hope in jython some how later( in near future) i thought…
And in the mean time, you may learn to love groovy and never want to go back.
Here is a limited groovy sample for adding some operator overloading to Vector3f…
[java]
import com.jme3.math.*;
Vector3f.metaClass {
multiply { Vector3f v -> delegate.dot(v) }
multiply { Float n -> delegate.mult(n) }
plus { Vector3f v -> delegate.add(v) }
}
Number.metaClass {
multiply { Vector3f v -> v.mult(delegate) }
}
[/java]
That supports scaling, adding, and dot products… pretty simple. The operator overloading in Number is to support things like 5 * vec versus vec * 5.
Is it so easy to implement like jython?
py = new PythonInterpreter();
py.execfile(“file.py”);
pspeed said:
And in the mean time, you may learn to love groovy and never want to go back. :)
Hahah, a Groovy ...lover is right here!
@mainclain:
Take a look at Groovy website :
http://groovy.codehaus.org/Embedding+Groovy
http://groovy.codehaus.org/Bean+Scripting+Framework
and you see how much power Groovy syntax bring to Java force :p
It's my most satisfied scripting language for sure (1st ) compare to others (clojure is standing next to it :p)
@pspeed:
Recently I 've thought about your game entity system in Mythura a lot
(Seem like you got a good one there)...
For my game, a small world RPG-typed game, the entity system is not necessary yet, because I want to keep it's small and simple... Everything is just working via scripting...
But some ideas still flying in my head about a "clojure entity system" for a few months.
Unfortunately I don't have enough knowledge of the language to make one.
mainclain said:
Is it so easy to implement like jython?
py = new PythonInterpreter();
py.execfile("file.py");
I will go one better and show you the way to do it that works with _any_ jsr-223 compatible scripting engine:
[java]
import javax.script.*;
....
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("groovy");
engine.eval( new FileReader("myfile.groovy");
[/java]
As long as groovy-all.jar is on your classpath then the above should work. Java 6+ includes JavaScript by default and most other Java scripting languages have support for jsr-223. I don't have the jython references handy but it should be just as easy as the above. Put the right jar on the classpath and use getEngineByName("jython") instead.
atomix said:
Recently I 've thought about your game entity system in Mythura a lot
(Seem like you got a good one there)...
For my game, a small world RPG-typed game, the entity system is not necessary yet, because I want to keep it's small and simple... Everything is just working via scripting...
But some ideas still flying in my head about a "clojure entity system" for a few months.
Unfortunately I don't have enough knowledge of the language to make one.
The entity system is what the scripts would use to manipulate the entity data. Mythruna will be heavily script driven, too. At the moment it doesn't really "do" anything so there aren't many scripts. But the AI and object behaviors will all be scripts as well as most of the client->server commands for user actions.
The nice thing is that with the DSL capabilities of something like groovy then I can even make most of the boiler plate disappear. So where in Java I might say player.setComponent( new Health(50) ); In groovy that would just be player.health = 50 or something. All TBD.
But the ES frees me from a lot of other garbage... and persists automatically in my case. It's worth considering.
I thought the hard part of a logic framework via scripting or sometime goal-driven is control “how player and NPC or many players interact with each other”…
Consider this one example tied with RPG type game:
A player see a book then decide to pick it up and read it…
In the normal situation, we code the player Object so it act like it know “every thing” and have a specific “method” to deal with any specific type of object or problem:
[java]player.find(abook).around(10feet);
if (abook!=null){
system.ask(“Do you want to read the book?”);
if (player.decide()==yes){
player.read(abook);
} else {
player.continue();
}
}
Class player {
public void read(book){ this.knowledge += book.value; }
//… More method to come
}
[/java]
so the pseudo code is :
[java]player.find()==ObjectThatKnownHowToDue
player.do(Object…)[/java]
and player class become bigggggggggggg …
Now, assume that the Player know not thing about what he seen, just let the “object” take care of the job in a Passive way :
In the script of a book:
[java]if (player.areCloseEnough(this.pos)
if (player.acceptInteract(this)
answer=this.tell(player,new Question(“Read or not?”));
if (answer==yes)
player.addKnowledge(this.value);
else
player.freeToGo();[/java]
So this type of script are suitable with RPG type game cause the number of Actor is just small (10 is max), so the Book just have to know 10 way to deal with 10 type of actor + some more situation… The first method is un-acceptable because Actor must know too much to deal with about other things…
Now my question : the prob in you game is MMO type, how can scripting be efficient for the job, a lot of choice and balance need for the script code writing???
pspeed said:
I will go one better and show you the way to do it that works with _any_ jsr-223 compatible scripting engine:
[java]
import javax.script.*;
....
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("groovy");
engine.eval( new FileReader("myfile.groovy");
[/java]
As long as groovy-all.jar is on your classpath then the above should work. Java 6+ includes JavaScript by default and most other Java scripting languages have support for jsr-223. I don't have the jython references handy but it should be just as easy as the above. Put the right jar on the classpath and use getEngineByName("jython") instead.
Hm okay cool, Jython works fine, groovy not :D
P/s: I forgot to ask: Is “Rule based world” somehow solve the “who act” and “who know what to do” problems…??
mainclain said:
Hm okay cool, Jython works fine, groovy not :D
Then something is wrong with the setup... that's nearly line for line what I have in Mythruna to run my event scripts. What errors did you get?
atomix said:
I thought the hard part of a logic framework via scripting or sometime goal-driven is control "how player and NPC or many players interact with each other"...
Consider this one example tied with RPG type game:
A player see a book then decide to pick it up and read it...
In the normal situation, we code the player Object so it act like it know "every thing" and have a specific "method" to deal with any specific type of object or problem:
[java]player.find(abook).around(10feet);
if (abook!=null){
system.ask("Do you want to read the book?");
if (player.decide()==yes){
player.read(abook);
} else {
player.continue();
}
}
Class player {
public void read(book){ this.knowledge += book.value; }
//... More method to come
}
[/java]
so the pseudo code is :
[java]player.find()==ObjectThatKnownHowToDue
player.do(Object...)[/java]
and player class become bigggggggggggg ..........
Now, assume that the Player know not thing about what he seen, just let the "object" take care of the job in a Passive way :
In the script of a book:
[java]if (player.areCloseEnough(this.pos)
if (player.acceptInteract(this)
answer=this.tell(player,new Question("Read or not?"));
if (answer==yes)
player.addKnowledge(this.value);
else
player.freeToGo();[/java]
So this type of script are suitable with RPG type game cause the number of Actor is just small (10 is max), so the Book just have to know 10 way to deal with 10 type of actor + some more situation... The first method is un-acceptable because Actor must know too much to deal with about other things...
Now my question :p : the prob in you game is MMO type, how can scripting be efficient for the job, a lot of choice and balance need for the script code writing????
(we're sort of getting off topic for this thread... but...)
This seems like a classic "does the knife cut the apple or is the apple cut by the knife?" style OOP question. When really, "cutting" is its own object that knows how to use a knife to cut something cuttable.
In an entity system you might have some component that is attached to an entity that contains its "read text". Any entity with one of these components might end up with a "Read" action in its radial menu... maybe its even the default action when you click on it. And maybe the two ideas are even more independent than that.
The entities that represent objects that the player can manipulate might have Action components, each of which corresponds to a script. These are what the player sees in his radial menu when clicking on the object and selecting one runs the script. The "Read" action then looks up the text data or whatever and displays it to the user. Perhaps there are standard actions that all object have like "look" and "take" or whatever that map directly to the user interface.
If actions require some distance to be performed then that is a property of the action not the object. I might be able to look at an object from across the room but I can only take it and/or read it if I'm standing right next to it. Also, if the object is a giant billboard then I can probably read it no matter how far away I am.
There are any number of ways to do this sort of thing, though. Mythruna will have a single Actions component with the list of actions that can be performed on an object. The individual actions either correspond to a built in function, a script, or a function in a script. The reason I've opted to do this is because to simplify my entity system, an entity can have only one of a particular type of component (ie: I can't have several separate Action components)... and because it's easy to control order and have things like default action slots for different UI mappings. (Perhaps left click always runs the first action and control-left click always runs the second one or something... where as right click will always bring up the full radial menu.)
Hundreds of ways to attack this particular problem.
@pspeed:
Yeah, got that clear enough for me to understand . Thank you!
@mainclain
And sorry the topic owner for those off-topic question, I just can’t resist! Any way , keep up your great work!
That’s no problem, perhabs I’ll find some good informations by that (like groovy
)
And it will be a while until I get a new Video so feel free to post as much as you want
Hey I am new to jmokey and read the whole scripting stuff in that post. I am interested in that part of extending the game.
So what are the benefits of scripting with e.g. python or groovy? Maybe I have the possibility to add new dialogue content without recompiling the whole game? I have only to add the new dialogue or extend or change an existing dialogue?
So can anyone explain me, how to use scripting in jmonkey or how it works? I have a big gap in my mind. Howe can I smoothly integrate the script and provide a information exchange between them. Is there a mapping for the functions necessary?
@mainclain
by the way nice work.
thank you for help.
hi guirius, you dont need to recompile the game when you change a dialog even when using classes.
you have a class data, you store its data in a xml file. So you dont need scripting.
Class pros :
- scripting has errors compiler didnt catch.
- scripting is slow.
- class can do the same thing, if you have programmed for that outcome from before.
Conclusion : use classes for base data. Use scripting for map creation, modifiable behavior your editor didn’t expect.
@tralala: interesting approach, but you can get to a point very soon when doing it with classes and data files / databases become too static. Eg. how do you handle the case where you have to change the condition on one branch of a conversation tree? How do you store these conditions in the first place?
@quirius:
I think you should ask in a new topic, cause we are hi jacking this topic too much…
Feel free to make a new topic to ask about scripting, I think many monkeys in this forum have experiences to share with you.
@tralala :
Scripting for dialog is a good choice, and scripting is not slow !! You have to write a whole big hard-coded “rule-base”,“goal-driven” system or “finite state machine” for a big game… In other hand, you can do simple and also complicated with script… Just our choice and the sacrifices for flexibility of course are speed and memory…
@anthyon : i will give an example of how it could be implemented (not started yet)
class DialogOption
{
private Condition isVisibleToPlayer ;
private String text ;
private CallbackMethod onAnswer ;
}
public interface Condition
{
public boolean isTrue(Object… arguments);
}
public interface CallbackMethod
{
public void call(Object… arguments);
}
You can say that it is static, and i agree but nothing prevents you from creating a subclass of CallbackMethod that runs a script instead.
Pros:
- engine internally doesn’t use scripting language = more speed.