🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Java as a scripting language

Started by
2 comments, last by trivierph 20 years, 2 months ago
Hi everyone. I am rather new here (some of you will notice it is my first post, but I have been browsing here for quite some time), and also rather new to scripting langage. I am involved in the programming of a small RPG in Java. I am considering using scripting. I have been looking at different languages , and I was ready to start using Lua (and some Java-Lua binding I found over the net). Yet I started figure out if using Java Reflexion might not be possible. My point is : from what I have read so far (please feel free to correct me ..), scripting seems to be based on binding functions from your engine with the scripting langage, and executing scripts that would use those bound functions, and would be stored in other files. The thing is to be able to change the logic of the game without having to recompile the core (engine) of the game. This leads to the use of scripting, virtual machine-based languages (Lua or other) that are only interpreted at run-time and not compiled. Though it is possible to compile scripts in order to make this execution faster. On then have to learn another language (which is not that bad, I admit), but also to prepare any methods / data structure binding in the engine. (BTW , I have often read that scriptionf was to be used by level designer / scripter / non-programmer persons ; yet , I don't really see yet in which way scripters are doing anything else but programming, since they have to play with a prog. language and the methods available in the engine. Anyone can enlighten me a bit ?) Now I considerd using a reflexive language like Java. If I create my scripts as classes implementing an interfacce with a run() or equivalent method, and I load it at runtime using reflexion, that should do the job, doesn't it ? Ex :

public interface IScript {
 public void run();
 //...parameters stuffs

}

public class Engine(){
 // ...

 String nameOfTheScriptClass = ... // name of the class

 /* The name of the script class would probably have to be read
  from another datafile, since you don't want your script names
  to be hard-coded. Anyway. */
 IScript script = (IScript) Class.forName(nameOfTheScriptClass).newInstance();
  // whatever

  script.run();
  // ...

}
I would compile this ONCE and only once (no I'm not an XP guru), then would write my script as pure Java classes, compile only thoses classes , and run the engine without any modifications. Naturally, I would probably have to had a generic mechanism to add property to the script classes (such as a
 addParameter(String _name, Object _value)   
methods, or something, to my scripts), but it sounds to me as it would do the job. Since I have never actually done scripting, I was wondering if that sounded ... sound to you. Has anyone done something like this earlier ? Otherwise, where could I find actual exemples of scripting implemented (and linked, don't tell me to go into mods ) in a game engine ? Thanks by advance for answers. Sorry for the spélingue misstaques, I am french, anyway [edited by - trivierph on April 12, 2004 10:31:49 AM]
Advertisement
There have been some discussion recently about doing exactly this with C#, and there is certainly nothing wrong with the idea.

Personally the scripting I use in my code is designed to be as light-weight as possible in that it doesn''t take too long be interpreted / compiled at run time. As far as I''m concerned scripting is a tool minimise development time which would normally be wasted in the code / compile / debug / run cycle.

Another factor to consider is that scripting is supposed to be easier to write and maintain than conventional code. If you (and the rest of your team) only know java that may be a good reason to use this a java only system. Java isn''t quite as bad as C++ where you need to worry about memory management, which is one reason scripting can be helpful.

If you''re comfortable with new languages I''d suggest Jython which is that Java port of python (which is supposed to be pretty good).

If there is a scripting language which is appropriate for modules of your system which you identify as high risk (something you think will go wrong and need to be scrapped at least once). Seriously consider that scripting language. ie/ if none of your team knows network programming pick something with good high level support for network programming.
Thanks. I''ll check the C# thing ...
Take a look at BeanScript. It uses java syntax and can access all your classes through reflection without needing to do any extra work.

This topic is closed to new replies.

Advertisement