Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
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  
  Utility of scripting language  (Read 1833 times)
0 Members and 1 Guest are viewing this topic.
Offline Gudradain
« Posted 2009-02-22 15:48:00 »

Hello, I'm a new member here.

I'm currently trying to make a game in Java and I'm doing a lot of research and experiment to see how things work before I really begin the project.

One thing I didn't find out is why many games use scripting language to handle the event/action. What is the big advantage of using a scripting language? So my general question is : why would I need a scripting language for my game if I need one? Is it that there is some sort of things I can't do in Java that I would be able to do with the scripting language?

Thx
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 835
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2009-02-22 19:06:13 »

You can do everything in Java, it's just a big husle sometimes. You can abstract away things that would normally require you to write many lines of code, time and time again. Also, you might want to change the behaviour of AI at runtime, and it would be a daunting task to keep compiling Java code and creating classloaders all the time. Further, if you want the community to write plugins, you might want to restrict what they can modify in the game, to prevent cheating - a limited scripting language is the only solution.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline jezek2
« Reply #2 - Posted 2009-02-23 03:59:44 »

Just what Riven said, though I'm not quite sure about the cheating argument, even when you can do less stuff, you still need have enough power to do nasty things otherwise you won't be able to create any proper scripts too.

Using Java for "game code" is possible too, and with a good API quite ok. One feature that scripting language often provides is the ability to stop/start the code at any point, so you can eg. write your logic as big while(true) { .. } and actually don't block the game. This is not achievable in pure Java (well it is with threads, but they're too much heavyweight and cumbersome for this task). But thanks to Matthias Mann's continuations library you're able to do this in Java too. I'm using this approach and it's pretty good, also it's being used for game code in Tribal Trouble 2.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #3 - Posted 2009-02-23 10:11:30 »

Scripting languages are more common when the core/engine code is in C or C++, where you've got to explicitly deal with memory management and may have to wait several minutes to compile after even a simple change. This makes writing your gameplay code in a higher level scripting language like Python or Lua much more appealing.

There's still benifits to using scripting for a Java game though, in particular it's nice to bundle up level-specific logic (like side quests in an RPG) into an external data file (either embedded inside your level data or alongside it) rather than having it clutter up your code with lots of extra Java classes.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #4 - Posted 2009-02-23 11:27:57 »

I am nto sure if XML is included in "scripting languages" but if so, you can just use a map editor, I.E tiled.

instead of wrting tons of code for the maps and levels and other in game  objects/places.
Offline Gudradain
« Reply #5 - Posted 2009-03-02 13:49:56 »

Thx for all the reply.

I finally decide to try a scripting language. I did some research on the web to find a good scripting language and I found out that groovy seems to be really popular to do scripting in java. So, I try it out and I have been able to put all the information about my map in a text file outside of java. I can even change my map while the game is running (just need to reload it).

For now, I would say that Groovy work very well. But my program is still simple for the moment so I wonder if it will always be the case.

Anyone has try Groovy? Do you like it, does it work well for well? Is it good for doing game?
Offline beni

Senior Newbie





« Reply #6 - Posted 2009-03-05 15:16:34 »

What i still wonder is how the interaction between java and the scripting language works.
How does one make Java objects available to the script? How to pass arguments or Variables around?
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #7 - Posted 2009-03-05 15:43:43 »

http://tinyurl.com/c5w5yb

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #8 - Posted 2009-03-05 17:50:36 »

If you don't need to change anything at runtime, I find that doing it all in Java and then just using the class loader works totally fine. I've done this as part of level files for certain games that might want to have unique logic in a level. Basically you save the class file with the level and then you execute it whenever you're in that level.

See my work:
OTC Software
Offline DzzD
« Reply #9 - Posted 2009-03-05 20:57:21 »

You can do everything in Java, it's just a big husle sometimes. You can abstract away things that would normally require you to write many lines of code, time and time again. Also, you might want to change the behaviour of AI at runtime, and it would be a daunting task to keep compiling Java code and creating classloaders all the time. Further, if you want the community to write plugins, you might want to restrict what they can modify in the game, to prevent cheating - a limited scripting language is the only solution.

I remember that you was working (with commanderkXXX oups.. dont remember his nick ) on a sandboxe to enable user specific class load, no ? this could enable java to be used as scripting/runtime language

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Gudradain
« Reply #10 - Posted 2009-03-06 04:42:19 »

What i still wonder is how the interaction between java and the scripting language works.
How does one make Java objects available to the script? How to pass arguments or Variables around?

Well, in Groovy the interaction between groovy and java is simple. All groovy file are parse and compile to .class so java can directly execute those file. To access java class from groovy you simply have to put an import package.className in the header of the groovy file. On the other side I didn't catch it yet... To dynamically load groovy file into your java program you can use a code similar to that :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
ClassLoader parent = this.getClass().getClassLoader();
        GroovyClassLoader loader = new GroovyClassLoader(parent);
       
        try{
            Class groovyClass = loader.parseClass(new File(mapLocation));
            GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
            Object[] arguments = {};
            mapInfo = (MapInfo)groovyObject.invokeMethod("run", arguments);
           
        }


There is one thing I would need a bit of explanation about. When we are talking about changing something at runtime does it mean loading a new map that we just create for example or would it rather be something more like the macro the player can write in Wolrd of Warcraft?
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.

trollwarrior1 (31 views)
2014-11-22 12:13:56

xFryIx (72 views)
2014-11-13 12:34:49

digdugdiggy (51 views)
2014-11-12 21:11:50

digdugdiggy (45 views)
2014-11-12 21:10:15

digdugdiggy (39 views)
2014-11-12 21:09:33

kovacsa (63 views)
2014-11-07 19:57:14

TehJavaDev (68 views)
2014-11-03 22:04:50

BurntPizza (66 views)
2014-11-03 18:54:52

moogie (81 views)
2014-11-03 06:22:04

CopyableCougar4 (81 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!