Put methods and objects in xml


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…


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

Kev

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

Glad it helped,

Yeah, I met/worked with mud developers who would quite happily learn 5 simplistic bespoke languages rather than one “real ™” langauge.

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

Kev

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?

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:


    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:


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

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.

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