Marauroa Core API: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>Hendrik Brummermann
imported>Hendrik Brummermann
Line 101: Line 101:
</source>
</source>


These methods add attributes to the RPClass and set their type and visibility. You can also set the parent of this class. Of course, however, a class can have no parent (be parentless).
These methods add attributes to the RPClass and set their type and visibility. You can also set the parent of this class. Of course classes without parents are possible, too.

Once the class has been filled, you can query the data using these methods. These methods allow you to get the class name of the class, the the type of an attribute, determine if an attribute exists and to know if that RPClass is a subclass of another.


Once the class has been filled, you can query the data using these methods. These methods alow you to get the class name of the class, the the type of an attribute, determine if an attribute exists and to know if that RPClass is a subclass of another.<br>
'''Query''':
'''Query''':
<source lang="java">
<source lang="java">
Line 113: Line 114:
</source>
</source>


You can query the system classes using these methods. Note that it is '''not''' a good idea to modify them once you are running. The class definitions are send to the client on connect hence if you change the class definitions in the middle of a game you will crash your clients!<br>
You can query the system classes using these methods. Note that it is '''not''' a good idea to modify them once you are running. The class definitions are send to the client on connect hence if you change the class definitions in the middle of a game you will crash your clients!

'''Class wide query''':
'''Class wide query''':
<source lang="java">
<source lang="java">
* ''boolean hasRPClass(String name)''
boolean hasRPClass(String name)
* ''RPClass getRPClass(String name)''
RPClass getRPClass(String name)
</source>
</source>


Line 128: Line 130:
// a general entity with a position
// a general entity with a position
RPClass objclass = new RPClass("entity");
RPClass objclass = new RPClass("entity");
objclass.add("x",RPClass.BYTE);
objclass.add("x", RPClass.BYTE);
objclass.add("y",RPClass.BYTE);
objclass.add("y", RPClass.BYTE);


// an entity specialized in players
// an entity specialized in players
objclass = RPClass("player");
objclass = RPClass("player");
objclass.isA("entity");
objclass.isA("entity");
objclass.add("name",RPClass.SHORT_STRING);
objclass.add("name", RPClass.SHORT_STRING);
objclass.add("dir",RPClass.SHORT_STRING);
objclass.add("direction", RPClass.SHORT_STRING);
objclass.add("score",RPClass.INT);
objclass.add("score", RPClass.INT);
objclass.add("super",RPClass.BYTE);
objclass.add("super", RPClass.BYTE);
objclass.add("!vdir",RPClass.STRING,RPClass.HIDDEN);
objclass.add("!vdir", RPClass.STRING,RPClass.HIDDEN);
objclass.add("!hdir",RPClass.STRING,RPClass.HIDDEN);
objclass.add("!hdir", RPClass.STRING,RPClass.HIDDEN);
objclass.add("?kill",RPClass.FLAG);
objclass.add("?kill", RPClass.FLAG);
</source>
</source>


Each time you create a new RPClass, as long as you give it a name ( ie: player, position, ... ), it will be added to the system list of classes.
Each time you create a new RPClass, as long as you give it a name (ie: entity, player, ... ), it will be added to the system list of classes.


Notice in the example that the HIDDEN attribute must be specified if you want the RPClass to have this property otherwise by default an attribute is visible.
Notice in the example that the hidden attribute must be specified if you want the RPClass to have this property otherwise by default an attribute is visible.


Note: You can choose not to use RPClasses in your application BUT the performance penalty will be big on bandwidth and CPU usage.
Note: You can choose not to use RPClasses in your application but that increases network bandwidth usage.


== RPAction ==
== RPAction ==