Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  A good scripting language for java games  (Read 8825 times)
0 Members and 1 Guest are viewing this topic.
Offline zingbat

Senior Member




Java games rock!


« Posted 2006-04-14 17:14:20 »

I read this article on the subject but i still can't decide if i trust the article:

http://www.javaworld.com/javaworld/jw-03-2005/jw-0314-scripting-p2.html

Im interested in a scripting language that uses Java syntax and can interpret Java code with classes and interfaces without any modifications like BeanShell but this is about 10x slower than Groovy and this is about 2 times slower than Pnuts and Rhino.

The size of the jar and the usabiliy of the api is also important.

So what do you think it's the best scripting language for java games?
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #1 - Posted 2006-04-14 17:32:41 »

Frankly, that article sucks. There are bits like the long warbling look at groovy closures as a "special feature" which suggest the author doesn't know that much (at least one of the other langauges and off the top of my head 3 of them also fully support closures).

The microbenchmark, of just one very limited set of ops, is IMHO almost a waste of time. The author apparently didn't even know WHY things got faster between JVMs, let alone delve into the ramifications of that (at a glance, I guess it was probably the improvements to reflective method invocation. He really needs to go and investigate the overhead from reflection going on there, and e.g. make a benchmark that emphasises and de-emphasisses that).

Finally, using just one set of ops? Compelte waste of time. You need to test a whole load of things. IMHO, the author is pretty damn lazy, seeing as it would have been pretty easy *for a scripting language review* to write some sensible "real" code - the point of scripting languages is to make writing real code very very fast and easy!

w.r.t. to beanshell, I'd suggest looking at the mailing list archives. They are are about 12-18 months overdue on a new release that would massively increase performance. I'm not subbed any more, so don't know why its still not happened, but I suspect its because time is goign instead on getting beanshell into JDK properly (c.f. the JSR's, beanshell now has its own JSR). I suspect they are wating to compelte that, then they will do the perf improvements that they roughly know how to do and would make a big difference.

malloc will be first against the wall when the revolution comes...
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #2 - Posted 2006-04-14 17:49:17 »

Why would you start a scripting language comparison with a set of performance benchmarks? The whole point of a scripting language (IMHO) is that you've using a considerably higher level language for places where development time is much more important than runtime performance. The most important thing for a scripting language should be how much productivity gain you're going to get from using it. Anything which becomes a bottleneck can be pushed into the Java side of things and exposed to the scripting layer.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline zingbat

Senior Member




Java games rock!


« Reply #3 - Posted 2006-04-14 23:04:47 »

The only reason i need a scripting language is for people who know litle of programing to script quests with it in a game remake im working on. Speed is important because scripts are going to run every frame with some sort of script loding mechanism. Im tempted to use Javascript because it's commonly known and looks like it has a stable development team and strong support behind it.
Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #4 - Posted 2006-04-15 02:00:00 »

I was experimenting with rhino at one time and I think it's about a 500kb jar.  I think you have the right idea as javascript knowledge seem pretty common and it is in fact a sweet little language.
Offline fazekaim

Junior Member




Java games rock!


« Reply #5 - Posted 2006-04-16 09:51:08 »

Hello, i'm using java 1.6.0 betas, and there is a Javascript engine built in the Java.
The Javascriupt code can communicate with Java codes(f.e.:call Java methodes, instantiating, etc.) and the Java code can communicate with the Javascript code (f.e.:change some settings, class javascript routines, etc.). So there is full interoperability.

I think, it's fast enough (inner compiling...), and it's an officially built in full-features script language.

I'm using it in my game project.

Sorry for my bad english.
Offline zingbat

Senior Member




Java games rock!


« Reply #6 - Posted 2006-04-16 20:28:29 »

Java 6 has a couple of good improvements to help scripting. From this article:

http://www.devx.com/Java/Article/30722/1954?pf=true

Quote
The new Java Compiler API allows Java source to be compiled from within a Java application. During compilation, the application has access to the library dependency information as formulated, along with any warnings, errors, and other messages that are generated. Although this feature did not seem like something I would use often, I quickly found new uses for it. To enable Java scripting, Java SE 6 supports JSR 223, a scripting framework that provides scripting language access to Java internals. You can locate scripting engines and invoke them to run scripts at runtime. The Scripting API allows you to provide Java support for the scripting language of your choice. In addition, the Web Scripting Framework allows script code to generate Web content within any Servlet container.
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #7 - Posted 2006-04-24 21:15:28 »

I'm using Groovy quite a lot these days - okay, it has some flaws, but it's well worth adding to your toolkit.  For XML generation, it's pretty unmatched.

As for speed, Groovy can compile down to bytecode (don't know if the OP's article mentions this - JW appears to be down), and while I know nothing about the quality of that bytecode, it's likely to be one of the faster scripting languages out there because of it.

Hellomynameis Charlie Dobbie.
Offline Jeff

JGO Coder




Got any cats?


« Reply #8 - Posted 2006-04-24 23:04:45 »

I guess I question the need for a scripting language at all.

Java code can be run-time loaded.  If you provide a decent API frankly I dont think ist any harder to write then any of the game-scripting lnaguages otu tehr and easier then many.

*shrig*

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #9 - Posted 2006-04-24 23:31:31 »

A decent API is one thing, but syntax, keywords, operators, layout etc are quite another - no one syntax can be correct in all situations.  Different languages have their place, just as Java has its.

Hellomynameis Charlie Dobbie.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #10 - Posted 2006-04-25 04:36:50 »

True, but most game scripting languages just crib their synatx from existing languages anyway (most often C.)


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #11 - Posted 2006-04-25 10:35:51 »

I guess I question the need for a scripting language at all.

Java code can be run-time loaded.  If you provide a decent API frankly I dont think ist any harder to write then any of the game-scripting lnaguages otu tehr and easier then many.

*shrig*

Yes, you can of course also use Java for scripting. However...
-the turn over rate isnt that nice (compilation takes a while... on slower machines its 30seconds vs some msec)
-tools.jar is rather big (6.8mb vs less than 0.5mb for any scripting language)
-long winded java syntax (thats no issue for me)

Using that compiler directly also looks pretty meh, because the documentation is somewhat lacking, it requires lots of parameters and it also needs disc access. It really isnt the best tool for the job.

弾幕 ☆ @mahonnaiseblog
Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #12 - Posted 2006-04-25 11:24:52 »

I'm with Jeff on this one. I would be very surprised if the number of people who would be making scripts is going to be large enough for these issues to matter:

Quote
-the turn over rate isnt that nice (compilation takes a while... on slower machines its 30seconds vs some msec)
But it only needs to be done once, at development time.

Quote
-tools.jar is rather big (6.8mb vs less than 0.5mb for any scripting language)
On the other hand, the population of scripters is going to be vastly smaller than the population of players. You'd probably reduce the download burden by having the scripters get the jdk, instead of everyone having to download some other scripting language.

Quote
-long winded java syntax (thats no issue for me)
As Jeff said, that's just a matter of API design.

IMHO, anyway.
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #13 - Posted 2006-04-25 12:06:31 »

>But it only needs to be done once, at development time.

Huh? Its not like you write the complete game in one go and everything just works perfectly.

Using a scripting language (and media caching) makes the process very interactive. You change a script, save, switch over to the game, press F5 (or whatever) and you see your changes in effect. Its really cool and lots of fun. Its super awesome for prototyping, because you can just go ahead and try differing things out, tweak variables and see how it feels etc.

>On the other hand, the population of scripters is going to be vastly smaller than the population of players.
>You'd probably reduce the download burden by having the scripters get the jdk, instead of everyone having to
>download some other scripting language.

I ment that its like that if you want to ship your game/application with build-in scripting abilities. I for one dont ship any extra script jars, because I just compile my stuff once I'm satisfied with it. And well, yea I'm fine with java syntax, because it allows me to do this Wink

Btw I'm using Janino for scripting. Its a very fast on-the-fly java compiler. So, I'm basically using java for scripting. My framework allows me to use any other scripting language if I want to. But I'm using this one, because its the only way to get full java execution speed. (WYSIWYG Wink)

弾幕 ☆ @mahonnaiseblog
Offline Jeff

JGO Coder




Got any cats?


« Reply #14 - Posted 2006-04-25 20:10:51 »

>But it only needs to be done once, at development time.

Huh? Its not like you write the complete game in one go and everything just works perfectly.

Using a scripting language (and media caching) makes the process very interactive. You change a script, save

Have you used Eclipse?

It compiles your Java on the fly whenever you save.  And its very fast Cool

 

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #15 - Posted 2006-04-26 00:00:52 »

Indeed.  But depending on who needs to be able to understand and update your scripts, Java may be entirely inappropiate for the task.

Try explaining to a non-technical game-designer wannabe (who you'd dearly love to be able to implement simple new game rules in your engine) why the length of a String is "length()", of a String[] is "length" and of a List<String> is "size()".  And explain how to interpret the error message which results when he gets it wrong.

Java is a great language, but appropiate for all tasks and for all people it is not! Wink

Hellomynameis Charlie Dobbie.
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #16 - Posted 2006-04-26 00:11:54 »

Eclipse yea... well, its pretty fast. But starting it in first place takes a while... eats lots of ram... then some swapping etc. Its pretty heavy. Whereas using a scripting language is more like writing html. Yea, its really like writing html. Also if you write over in eclipse, save, switch over, press reload... then there is no gurantee that eclipse is done with compiling. (Using jdt for compiling directly is certainly more appealing.)

弾幕 ☆ @mahonnaiseblog
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #17 - Posted 2006-04-26 04:52:58 »

Also if you write over in eclipse, save, switch over, press reload... then there is no gurantee that eclipse is done with compiling.

Eclipse tells you when it is building on bottom right corner of the Eclipse window.  In the rare case when it isn't instantaneous (e.g. it has to rebuild the workspace) you can easily wait until it is done.

But more to the point.. you could probably use BeanShell to prototype some aspects in an interpretted mode and then provide the final compiled classes for distribution.   Keeping things Java would simplify some aspects of the scripting, though Java 6 will have the proper scripting support for all sorts of scripting languages, so that might make more sense.

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #18 - Posted 2006-04-26 07:03:07 »

There isnt much of a reason to use a less optimal tool. Watching some corner... having to wait eventually... nah... why should I bother with that?

>But more to the point.. you could probably use BeanShell to prototype some aspects in an interpretted mode
>and then provide the final compiled classes for distribution.

Thats pretty much what I do (as I said). But I use janino instead of beanshell. At the end I just compile it and change a line in a configuration file... thats it.

>Java 6 will have the proper scripting support for all sorts of scripting languages

If you grab that jsr jar you can use it right away with 1.5. However, I didnt found it useful at all. Its not suited for scripting complete classes (see above)... its more of a lowest common dominator thing (and usually you cant script complete classes). I guess its fine for usual scripting tho.

弾幕 ☆ @mahonnaiseblog
Offline zingbat

Senior Member




Java games rock!


« Reply #19 - Posted 2006-05-01 00:19:47 »

Using a scripting language (and media caching) makes the process very interactive. You change a script, save, switch over to the game, press F5 (or whatever) and you see your changes in effect. Its really cool and lots of fun. Its super awesome for prototyping, because you can just go ahead and try differing things out, tweak variables and see how it feels etc.

I haven't think about an option to reload scripts at play time but thats a good idea for prototyping which is what i want to do. I  will have to rethink my proto game architecture to separate the static model from the dynamic model but i thibk it will be worth.

I'm using Javascript at the moment which is E4X  enabled:
http://www.ecma-international.org/publications/standards/Ecma-357.htm
Nothing beats E4X when working with xml.

I'm remaking the spaceinvaders demo to work with javascript. I'm working with scripts controling each entity. I have scripts for Alien.js, Ship.js, VictoryScreen.js, PauseScreen.js,DefeatScreen.js,ShotScreen.js,GameMaster.js. Each script only has to provide these methods: void initialize(), void setup(), void cleanup(), void update(), void present(). Communication is made trough an hosted Javascript object called Game that forwards all calls from entities to the game master script that controls the game rules and decides what call should be satisfied and in what circunstances.

Some methods of the Game object:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
Game g = Game.get();
g.setSpeed(this,100);
g.setDirection(this,angle);
b=g.canShot(this)
shotid=g.shot(this)
b=g.gotHit(this)
b=g.isDead(this)
t=g.getTime(this)
kc=g.getKeyPress(this)
mc=g.getMousePress(this)
x=g.getMouseX(this)
y=g.getMouseY(this)
sch=g.schedulle(this,wakeup_cond)
state=g.getEvent(this,sch)
...


Doesn't sound too hard to learn except for the schedulle event part. But that is just a scheduller i can use to tell the game to call me back which i can check with a g.getEvent(this) once wakeup_cond has triggered (still working on this). Plus Javascript is not delaying the game in any noticeable way.
Offline benjamin

Senior Newbie





« Reply #20 - Posted 2006-05-16 20:44:37 »

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?
Offline shawnkendall

Senior Member





« Reply #21 - Posted 2006-05-16 21:10:17 »

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 :-))

Shawn Kendall
Cosmic Interactive, LLC
http://www.facebook.com/BermudaDash
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #22 - Posted 2006-05-16 22:07:22 »

[...]
I'm remaking the spaceinvaders demo to work with javascript. I'm working with scripts controling each entity. I have scripts for Alien.js, Ship.js, VictoryScreen.js, PauseScreen.js,DefeatScreen.js,ShotScreen.js,GameMaster.js. Each script only has to provide these methods: void initialize(), void setup(), void cleanup(), void update(), void present(). Communication is made trough an hosted Javascript object called Game that forwards all calls from entities to the game master script that controls the game rules and decides what call should be satisfied and in what circunstances.
[....]

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.

弾幕 ☆ @mahonnaiseblog
Offline zero

Junior Member





« Reply #23 - Posted 2006-05-16 22:44:04 »

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.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 742
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #24 - Posted 2006-05-16 22:54:34 »

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.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline benjamin

Senior Newbie





« Reply #25 - Posted 2006-05-23 09:24:40 »

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.
Offline Breakfast

Senior Member




for great justice!


« Reply #26 - Posted 2006-05-25 12:07:10 »

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.
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #27 - Posted 2006-06-18 08:52:00 »

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. Smiley

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.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline stramit

Senior Newbie





« Reply #28 - Posted 2006-06-24 17:11:11 »

Quote
-tools.jar is rather big (6.8mb vs less than 0.5mb for any scripting language)
On the other hand, the population of scripters is going to be vastly smaller than the population of players. You'd probably reduce the download burden by having the scripters get the jdk, instead of everyone having to download some other scripting language.

Also it is against the sun license to redistribute tools.jar..... just a head up for anyone that is doing it.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (33 views)
2014-07-18 06:55:21

Zero Volt (29 views)
2014-07-17 23:47:54

danieldean (24 views)
2014-07-17 23:41:23

MustardPeter (26 views)
2014-07-16 23:30:00

Cero (41 views)
2014-07-16 00:42:17

Riven (43 views)
2014-07-14 18:02:53

OpenGLShaders (31 views)
2014-07-14 16:23:47

Riven (30 views)
2014-07-14 11:51:35

quew8 (29 views)
2014-07-13 13:57:52

SHC (64 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!