Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  Put methods and objects in xml  (Read 2437 times)
0 Members and 1 Guest are viewing this topic.
Offline MickeyB

Senior Member




my game will work, my game will work!


« Posted 2005-03-03 16:52:57 »

Craaaazy question...

Does this sound feeeeesable? Write a method called process like so...

1  
2  
3  
4  
5  
public void process(string cmd, string parms) {
      // get the cmd
     // get the num of parms by parsing string by delimeter
              // do something
}


Use the cmd string to find the a matching xml node in an xml doc. Then get the number of parameters by parsing the parms on a pre-determined delimeter.  Check xml for matching parm count for the cmd node.
Then use this the parms to do some type of action on the parms and send results back to parent app.

How would one "do the action" based on data from the xml node for that cmd?  


Example use: chat server where an admin might add a new xml node by sending the following string:
create @method wink @param-usera @param-target @action write[usera 'winks at' target]

the app would add an xml node like so:
1  
2  
3  
4  
5  
6  
7  
8  
<methods>
      <method name="wink">
            <paramCount>2</paramCount>
            <param>user a</param>
            <param>target</param>
            <action>usera 'winks at' target ( to server out channel)</action>
      </method>
</methods>


Then if a user, say kevgalss, types: wink blah3

room would get the result: kevglass winks at blah3

Where I am lost is the action part, how to get this to function.

Another example: drop blah3
result: the action would be to find the blah3 object and disconnect it.

Another example: poke blah3
result: the action may be to add one irritation point to blah3 and send: kevglass pokes blah3
if irritation points grow to over 20 for kevglass, blah3 would auto ignore kevglass

The goal here is to build a core for the chat server (or MUD that comes to mind as I write this) and then the person using the core could create his own emotes, actions, commands, etc...

My apologies for using members in the above theatrics. Wink  There is no compensation as the play has no financial backing.

EDIT: the more I think about it, this could be a good mud core with action of attack, etc...that have to be pre-built by an admin/dev, etc...

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #1 - Posted 2005-03-04 19:40:29 »

After a little work, I found that doing the emotes (not actually affecting the object) are fairly easy from xml.  Now on to affecting objects, and making them.  Got a piece of code to work that creates a java file, compiles it and loads the class all from an active app.    This has to get me closer... Smiley

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #2 - Posted 2005-03-04 19:53:53 »

for my PoolSplash game I wrote code that would generate a level, put it in a .java file, compile it, load it, and test it.  If it was solveable, it'd keep it, if it wasn't, it'd delete it.  Then it would generate another level Smiley  I generated like over 1500 levels before weeding them down to 300.

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #3 - Posted 2005-03-04 20:25:49 »

/me is honoured, but doesn't feel so happy about being poked...

Anyway, what you *really* want to do is forget this XML malarky, and use beanshell.org scripts for each instead.

that way, your users write simplified java, and you can load it from a file or from a string and it is TRIVIAL to integrate with any existing java code.

Example source from survivor will go online sometime a few weeks after GDC. Only...that's when our commercial game launches, so maybe a few weeks after that Sad.

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

Senior Member




my game will work, my game will work!


« Reply #4 - Posted 2005-03-07 13:28:02 »

I plan on researching bs, but in themeantime, how are classes, objects, methods created, altered by beanshell stored on the server?  class or java file or both, if the system runs for 40 days and has many chagnes done "live" to it, then it is shutdown for some major code changes, are the runtime changes accessible to an api app like jbuilder or such?

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #5 - Posted 2005-03-07 14:11:50 »

Just use getDeclaredMethod(String name, Class[] parameterTypes) or getMethod(String name, Class[] parameterTypes) from the Class Class.  Provide the name of the method you want and the array of classes for the signature of the method you want.  For primitive types, you use the class value TYPE.  Integer.TYPE is the class of the primitive int.

Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #6 - Posted 2005-03-07 16:34:19 »

one last bs question:  does this mean I can make these changes/calls from my telnet prompt while communicating with the app.  IE  in chat or connected to a mud?

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #7 - Posted 2005-03-07 17:04:29 »

When you are connected with Telnet, then when you send the command it creates/updates an XML file?  If so, then you would have to re-read the XML file to execute the command.

If you already have the XML file loaded and it is just a reference of available commands that you can send over Telnet, then yes.

As long as the class and method exists as you define in your call to getMethod(...)

The thing you need to be sure of is the type of the parameters in the XML file.  It looks like they might all be Strings.  If that is the case, then it is easy.  If not, then you would have to modify the XML or know based on the param values what the class type would be.

Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #8 - Posted 2005-03-08 12:53:51 »

and CapnJester, you are talking about beanshell?

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #9 - Posted 2005-03-08 17:32:41 »

No, I am talking about using XML and Reflection.  I am not sure about what exactly you are trying to do, but you can create any class that exists in the classpath with Reflection.  You can also invoke any method that exits in a class as well.  So it is just a matter of how you want to communicate it through your program.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #10 - Posted 2005-03-09 14:05:36 »

To be honest, I was working on a chat server for a friend that would be a base core.  When connecting with telnet (or a chat client using telnet protocols), he could type something like:
create emote @target smile [$n smiles at $target]
or something similar and add the "smile" command to the system.  After tinkering with this, I found I could do this with XML and have a single method that would take x number of args and use the xml definitions to find the command and apply the appropriate args.  
Then I said to myself....this could solve a mud issue I was mulling over some time back.  Build a core, then xml the method definitions, objects, etc.. and let devs create much of the functionality as well as builders build the world.  I have seen examples done, but they almost all have only done the emotes.  What I can't figure out is how to allow devs to add new methods/objects and the like that affect other objects.

example:  the core is done with a bunch of emotes.  Now a dev comes on line and types:
create go @target [other stuff here] and it would add a command/method that would allow the invoking user to "go 1456" and have his character moved to room id 1456.  Or
create drop @target stuff stuff [more stuff] or whatever and this would create a drop command for a user to "drop knife"

The method drop will not have existed in any file, java or class, before that time.

I can do the emotes, can't do the things that effect/change other objects.

sample emote, as you can see it is striclty string manipulation and returns that string to all connected(in room) need to figure out how to do the same but $n cast magic at $N and get the results and effect the target, etc..
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
<EMOTE NAME="smile">
  <NO_ARG>You smile happily.</ACT_NOTARG>
  <ROOM_NO_ARG>$n smiles happily.</PER_NOTARG>
  <SELF_BAD_ARG>There's no one by that name around.</ACT_BADTARG>
  <SELF_SELF_ARG>You smile at yourself.</ACT_ACTTARG>
  <ROOM_SELF_ARG>$n smiles at $mself.</PER_ACTTARG>
  <SELF>You smile at $M.</ACTOR>
  <TARGET>$n smiles at you.</TARGET>
  <ROOM>$n beams a smile at $N.</PEERS>
</EMOTE>


Basically, allow devs/admins to "code" mud object and functionality through type string while connected and active as a user/player in the mud, store the changes and make them available.  Also, if the system is ever stopped, the "core" could still be edited in JBuilder (or the like) and when recompiled, all the admin/dev run-time added features will still be there.



asking too much?

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #11 - Posted 2005-03-10 10:21:29 »

Sorry.  I can't see how they could add commands like that without some kind of backing framework.

Offline kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #12 - Posted 2005-03-10 10:37:44 »

How did I miss this one!?!?  Smiley

If you want to do as you say a couple of posts up (without using BeanShell, which would be easier but would force your MUD devs to know a bit java syntax) you must first decide what your core objects are. For instance, if we're talking about MUDs maybe:

Room
Actor
Object

Is enough? Then allow setting and getting of properties on these objects, i.e. make them beans really. Now command definition has some powerful tools to play with, you go command:

1  
create [go target] [set ${player} location ${target}] [display You move to ${target.name}]


Where the generic form of the create command would be

1  
create <command_spec> <instruction 1> <instruction 2> .. <instruction N>


Where command spec is:

1  
[<command name> <parameter description>]


And instructions are defined as:

1  
2  
[set <entity> <property> <value>] 
[display <message>]


You'd have to have a relatively sophiscated infrastructure behind it to cope with converting from ids/tags/names to entities and back again, but not too tricky really. Specially not for you Wink

Sync the command defs to XML, load them at startup.. lovely.

And before anyone starts on me, yes its defining a new language for the sake of it. And yes it might be easier in bean shell. It might make it easier for devs somewhere tho.

Kev

PS. 'kevglass winks at Blah3'

Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #13 - Posted 2005-03-10 11:43:06 »

Thanks kev.  My devs will more than likely not know java.  I had started down that path with mudobject as the base object, then location/room and so on from it.  with some core methods on it.  I just thay my brainfreeze to get the concept onto paper then code, though I think I was close with the first post.


PS: kev, slow down, everytime you finish and start a new game, I get the urge to start a new one, but unlike you.... I ain't finish'd'others yet!   Grin

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #14 - Posted 2005-03-10 11:45:11 »

Quote

PS: kev, slow down, everytime you finish and start a new game, I get the urge to start a new one, but unlike you.... I ain't finish'd'others yet!    


Hehe, I don't tend to finish many either, they do get quite far along, but never finished to my standards.

I'm trying a new tactic at the moment to help me slow down, I'm working on 3 projects at once Smiley

Kev

Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #15 - Posted 2005-03-10 12:13:34 »

just 3 ?   Tongue  Grin

LOL

EDIT:  Beans within beans from xml....lovin it!  Found a nice xml - bean example and looks good.

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #16 - Posted 2005-03-11 16:34:40 »

Am I asking to much for the ability to....

Say you have the actor object.  Very simple, name, type, hitpoints/lifpoints/hull and some simple methods to effect those.

What if I wanted to allow devs to add a new variable to the actor or a class that extends it?  for example, the dev decides he/she wants to add a profession variable and the ascociated gets and sets....  could this be done with the "command and xml" theory as well?  

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #17 - Posted 2005-03-11 17:59:08 »

This is what I was trying to get out above about just assigning properties to entities. There may be some require properties, like location for actor, but this makes it very flexible.

Its even better if the properties are string -> object mappings. That way an entiy can have a another as a property value. All entities should be stringable so that the text based stuff can work.

Kev

Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #18 - Posted 2005-03-12 01:24:11 »

Yeah I was thinking hash table with string keys...


MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #19 - Posted 2005-03-14 12:41:53 »

Please excuse my supreme brain freeze, lack of knowledge, and complete clubieness on this... but I think what I am asking below will definitely require recompile and code on the dev part...unless I am looking right at kev's suggestion and not seeing it.  I understand having a table of objects for properites, and that an actor or object may have another as a property(neat)...but as for devs altering the following where I have added the question to the code below:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
abstract class Command {

      Object initiator;
      Object target;
      String...

      public Command(String[] args) {
           
            set stuff here..
     
      }
     
      public void execute() {
            how can a dev alter what this does on creation or edit?
      }



}

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #20 - Posted 2005-03-14 13:51:22 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
public interface Instruction {
   public void execute(Entity target, ArrayList arguments, World world);
}

public class Entity {
   private HashMap properties = new HashMap();

   public void setProperty(String name,Object value) {...}

   public Object getProperty(String name,Object value) {...}

   public void addPropertyListener(PropertyListener listener);
}

public class Command {
   private ArrayList instructions = new ArrayList();

   public Command(String defOrXML) {
       // parse definition into instruction objects here
  }

   public void execute(World world, String commandLine) {
      // parse command line, determine target and
     // argument strings

     for (int i=0;i<instructions.size();i++) {
        Instruction current = (Instruction) instructions.get(i);
     }
  }
}


and breath...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
public class SetPropertyInstruction implements Instruction {
     public void execute(Entity target, ArrayList arguments, World world) {
        target.setProperty(arguments.get(0).toString(),arguments.get(0));
    }
}

public class DisplayInstruction implements Instruction {

     public void execute(Entity target, ArrayList arguments, World world) {
          StringBuffer buffer = new StringBuffer();

          for (int i=0;i<arguments.size();i++) {
               buffer.append(arguments.get(i).toString());
          }

          world.display(buffer.toString());
    }
}


So the main game adds itself as a property list to all the character entities create. The world has a specialized property called "location" which when it changes it moves the player.

The devs come along, define a command that using the defined instructions modifies the "location" property which cause the character to move (i.e. climb rope).

Finally, if you like, you can add more instructions and improve what the devs can do.. you might add a comparison instruction that prevents the list of instructions continuing if it fails.. then you could have

define buy $item {check $player.invent includes gold} {setProperty $item location $player}

Essentially you end up defining your own little programming langugae. It'd probably be simpler just to let them use java Smiley

Kev

Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #21 - Posted 2005-03-14 15:40:58 »

dang....beautiful!  and this goes to show how you pump out 5 games an hour.

Now to get your goat....
If my devs knew java, but none of us know beanshell, could the same be accomplished through runtime exec calling compile after there strings are written to a java file and then class loading and unloading?  ( though many mud devs I know are used to, and like, quirky little in game languages for dev work Smiley )

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #22 - Posted 2005-03-14 16:02:18 »

Glad it helped,

Yeah, I met/worked with mud developers who would quite happily learn 5 simplistic bespoke languages rather than one "real (tm)" langauge.

Let us know how it all goes and what you decide,

Kev

Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #23 - Posted 2005-03-14 16:51:24 »

thanks!

Got a compiler and classloader going (but it wont recongize changes to the method unless I stop and start the jvm, which kills the point)  

anyway, as usual, will keep you posted unless a new game idea comes along Wink

thanks again!

EDIT:  do I need to pre design the instructions, like DisplayInstruction?  like create?

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #24 - Posted 2005-03-18 16:37:03 »

Now I have some combo test and gave BeanShell a whirl.  Though this is the first time I have used it, so I have jsut touched the tip of the proverbial iceberg...

this code in my java class:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
    public void reset() {
        i = new Interpreter();
        try{
                   i.source("stringScript.bsh");
                 name = (String)i.eval("getName()");
                 System.out.println(name);
        }
        catch(Exception te) {
        }
                 
    }


calls this script:
1  
2  
3  
String getName() {
      return "Mickey";
}


and I can edit the script and click my reset button and the change is beautiful!!    so far so good....  And I can still do a pseudo lang for my devs and have it write the bsh files...
hmmmmmm.....  now to figure out what to use where and how...LOL

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #25 - Posted 2005-03-20 11:36:37 »

Can anyone send a BSH newbie boob in the right direction.  I read in the docs that you an't yet create object from classes in the scripts, is this true?

Can you extend a class? If so, what would the script look like? The mailing list has been awful quiet.

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #26 - Posted 2005-03-23 17:31:08 »

yahoo.... have BSH in place for commands.  Running pretty well.  


MickeyB

Current Project: http://www22.brinkster.com/mbowles/
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.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (20 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

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

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

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

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

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

Riven (55 views)
2014-07-14 18:02:53
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!