Modding:TreeAttribute: Difference between revisions

From Vintage Story Wiki
no edit summary
No edit summary
No edit summary
Line 1: Line 1:
A TreeAttribute is a nested data structure whose primary purpose is to store data. It can hold generic data for most primitives, such as int, string, float, etc. This data can be stored and accessed using a key or index. It is also possible to serialize data and store it as a byte array. See also [[data serialization]].<br>
A TreeAttribute is a nested data structure whose primary purpose is to store data. It can hold generic data for most primitives, such as int, string, float, as well as more complex types like ItemStacks and other TreeAttributes (hence a nested structure).  
 
Additionally you can store data as byte[] if it is not supported by the TreeAttribute itself (for this you could use <code>Vintagestory.API.Util.SerializerUtil</code>).
Attributes are written and read via keys.


To use TreeAttribute, add the using statement for '''Vintagestory.API.Datastructures'''.<br><br>
To use TreeAttribute, add the using statement for '''Vintagestory.API.Datastructures'''.<br><br>
== Use in API ==
== Use in API ==
Within the API, TreeAttribute is often employed to store persistent entity data, and to access data extracted from JSON files. '''TreeAttribute''' is often supplied as the interface '''ITreeAttribute'''.<br>
Within the API, TreeAttribute is often employed to store persistent entity data (items a basket contains, content of a barrel/bucket) and to access data extracted from JSON files. '''TreeAttribute''' is often supplied as the interface '''ITreeAttribute'''.<br>


== Example in code ==  
== Example in code ==  
47

edits