Marauroa 3.8: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>Hendrik Brummermann
added navigation
imported>Madmetzger
Line 44: Line 44:
; Reason for change : There are many kinds of map like data structures in Stendhal (buddy list, ignore list, quest states, visited zones, ...). The previous way of using an RPSlot with exactly one RPObject was inconvenient.
; Reason for change : There are many kinds of map like data structures in Stendhal (buddy list, ignore list, quest states, visited zones, ...). The previous way of using an RPSlot with exactly one RPObject was inconvenient.
; Impact on Marauroa users : There are new methods in RPObject to work with the maps
; Impact on Marauroa users : There are new methods in RPObject to work with the maps
; Details : To use a map attribute you need to define an attribute with type map in the RPClass. It is done the same way as ''normal'' attributes for Strings or Integers. Here a short example on how to define a map attribute as it is done in Stendhal for the buddy list:
; Details : todo

player.addAttribute("buddies", Type.MAP, Definition.PRIVATE);

Afterwards you can access the map with several methods defined in RPObject to put or get values. To put a key value pair in a certain map you need to call the put method for maps:
rpobject.put(mapname, key, value);

To get a value stored for a key in a map you need to use the get method for maps:
rpobject.get(mapname, key);

The put and get methods provide methods to store/access String, Integer and Boolean values like they are provided for the existing attributes.
public void put(String mapname, String key, String value)
public void put(String mapname, String key, int value)
public void put(String mapname, String key, boolean value)
public String get(String mapname, String key)
public int get(String mapname, String key)
public boolean get(String mapname, String key)

If you need to check if a certain map is present in a RPObject you can to this by calling
rpobject.hasMap(mapname)

It returns true if within the RPObject has a map with mapname and false if not.


== Performance optimization ==
== Performance optimization ==