Element tree: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 13: Line 13:
In this example, the ''vehicle'' element's parent is the ''marker'' element. As such, we call the vehicle element a ''child'' element of the ''marker'' element.
In this example, the ''vehicle'' element's parent is the ''marker'' element. As such, we call the vehicle element a ''child'' element of the ''marker'' element.


All elements in a map are contained within the ''map'' node. We call this the ''root'' node, and it has to exist in every map file.
When this map is loaded, it is placed within the server's element tree. This tree has a number of "special" elements.
 
* A root element. This is at the very base of the tree - all elements are children (or grand children etc) of this element.
* Resource elements. These are direct children of the root element - with one for each ''running'' resource.
* Map elements. Each resource element contains at least 1 map element, representing either a ".map" file in the resource or containing the elements created by scripts (this is called the "dynamic" map).


Elements can have as many children as they like. This does not directly affect the map in any way, but it comes in to its own when combined with the scripting system.
Elements can have as many children as they like. This does not directly affect the map in any way, but it comes in to its own when combined with the scripting system.

Revision as of 21:40, 25 June 2007

MTA uses a so-called element tree to store the elements that make up the map. This is directly related to the XML map file's layout, although it can be changed at run-time by scripts.

If you are familiar with the concept of trees in computer-science, this should be easy to understand. If you are not, think of it like a family tree - except everyone only has a single parent. Every element has a parent element. This element is the element that it is contained within in the map file. For example:

<map>
   <marker>
      <vehicle/>
   </marker>
</map>

In this example, the vehicle element's parent is the marker element. As such, we call the vehicle element a child element of the marker element.

When this map is loaded, it is placed within the server's element tree. This tree has a number of "special" elements.

  • A root element. This is at the very base of the tree - all elements are children (or grand children etc) of this element.
  • Resource elements. These are direct children of the root element - with one for each running resource.
  • Map elements. Each resource element contains at least 1 map element, representing either a ".map" file in the resource or containing the elements created by scripts (this is called the "dynamic" map).

Elements can have as many children as they like. This does not directly affect the map in any way, but it comes in to its own when combined with the scripting system.

If you call a set... function on a node of the element tree, the function will affect every element within it (that it can work on).

So, the following code would set the size of every marker (the only type of element the setMarkerSize function can work on) that is below the root element to 2.5.

setMarkerSize ( getRootElement(), 2.5 )

The same can be done on any element, it is not restricted to the root element.