Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Scripting

Started by wicked_wesley Jan 27, 2004 at 3:49 PM 4 replies 450+ views
Original Post
wicked_wesley
wicked_wesley
Hi there, I'm working on a Java game (like everyone here ) and I have thoguht up something. In my game (RPG-alike) there will be alot of items, weapons, etc. (almost) Every item can be used, alone or with other items. If you use an item, probaly a couple of functions will be called, like this: giveExp(100); decreaseHP(2); ... You get the picture. Because alot of items will be used, I was think, should I make a scripting system, rather than some kind of large switch statement(this would make my code hard to read and edit) Every script could be put into a file, so it's easy to edit and to add. To use a class for every item would probally be an overkill, since there will be alot of items. My question is, should I do it like that? Are there any other ways? Oh the game will be client/server type, so the use of plain text files containing the script isn't an issue Thank you in advance! Wesley [edited by - wicked_wesley on January 27, 2004 4:51:38 PM]
Have a nice dayWesley
nonnus29
nonnus29
quote:
You get the picture. Because alot of items will be used, I was think, should I make a scripting system, rather than some kind of large switch statement(this would make my code hard to read and edit) Every script could be put into a file, so it''s easy to edit and to add.


I remember when I first had this revelation although mine was more in like ''How the hell am I going to switch levels in this thing?''

Sure you can create your own scripting language etc, but its ALOT of work. There are several excellent scripting languages you can embed in Java and they are as easy to use as falling out of your chair:

rhino - &#106avascript (my favorite)
Jython - python
JLua - lua (seems to be dead)

There are about 150 more here:

http://grunge.cs.tu-berlin.de/~tolk/vmlanguages.html
justo
justo
quote:
Original post by Anonymous Poster
Overall this is a good approach. My recommendation, however, is not to create a class for each Item, but create a single item class (or one for each category of item) and have it contain variables that can represent all the different traits of any item. That way, you can loop through your item script file, and just instantiate a new Item for each entry, and fill it with variables from the file entry.



if you do go with this idea, and if you dont mind the extra source files, this would be a good place to use an interface...that way you wouldnt have a bunch of wasted variables and methods, but you would have a standard way of interacting with an item, reagardles of type.
wicked_wesley
wicked_wesley
Thank you all for your help, I already looked to JPython, looks kinda good, I'm gonna check pnuts now Justo, could you explain a bit more what you mean, 'caus I don't really get it I really appericiate(sp?) your input.

Thanks,
Wesley

[edited by - wicked_wesley on January 28, 2004 3:25:25 PM]
Have a nice dayWesley

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.