Instance is a small scripting language for Java. It allows the user to describing how to setup new instances of a class and then create them at run-time. For example if you are making an RTS you might create a 'Unit' class that stores the code relating to the Units attack damange, movement speed, defense points, hit points, the image they should use and so on. You then create sub-classes of Unit (i.e. 'Knight', 'Archer', 'Infantry', etc) to state what these values are. Instead you can describe their fields using Instance and apply these descriptions to new instances of Unit. With instance you are not hard coding units stats and the description files can be reloaded whilst the game is running. The library consists of a single class, the InstanceFactory, that provides simple methods for loading scripts and creating new instances with them. [h2]Links[/h2][ul] [li][url=http://diablosdevil.googlepages.com/instance.zip]Instance Distribution[/url][/li] [li][url=http://diablosdevil.googlepages.com/InstanceFactory.html]Documentation[/url][/li] [li][url=http://diablosdevil.googlepages.com/instance_example.zip]Example[/url][/li] [li][url=http://diablosdevil.googlepages.com/instance_project.zip]Instance source code (a NetBeans project)[/url][/li][/ul] [h2]Technical[/h2] [ul][li]Compiled for Java 5, but only tested on Java 6.[/li] [li]Both 'instance.jar' and 'java_cup.jar' are required for this to be used.[/li] [li]java_cup.jar is a build of the Cup grammar for Java, more info at [url=http://www2.cs.tum.edu/projects/cup/]the home page.[/url][/i][/ul] [h2]Syntax[/h2] The Syntax is based on Java. Only primitive types and strings can currently be set. Example Instance script: [code]/* * Example instance file. * * It defines the setup code for three instances, * Knight, Archer and Infantry. * * @author: Joseph Lenton * @date: 31/01/2009 */ // an archer and infantry description that uses // method calls when setting themselves archer { setLocation(10, 20); } infantry { setName("simon"); setDefense(50); setHuman(); } // The Knight sets it's fields directly knight { x = 5; attack = 6.9; acceleration = 1.5f; name = "jeremy"; isRightHanded = true; } [/code][ul][li]'knight', 'archer' and 'infantry' are the names of the setup descriptions. The following block of code describes how to setup up a new isntance.[/li] [li]Only field declarations and method calls can be made in the block of code.[/li] [li]The fields stated must exist in the class used when creating a new instance.[/li] [li]All lines must end with a semi-colon or an end of line character.[/li] [li]Types supported are: integers, floats, doubles, longs, booleans, null and strings.[/li] [li]The class used for making new instances [b]must[/b] have a no argument constructor.[/li][/ul] Example usage in Java: [code]InstanceFactory factory = new InstanceFactory(); factory.load(new File("./example.inst")); Unit unit = factory.newInstance("archer", Unit.class);[/code] This post is from -- http://socoder.net/index.php?topic=0