Modding:TreeAttribute: Difference between revisions

From Vintage Story Wiki
Line 3: Line 3:
TreeAttribute 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.<br>
TreeAttribute 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.<br>
It is also possible to serialize data and store it as a byte array. See [[data serialization]].<br><br>
It is also possible to serialize data and store it as a byte array. See [[data serialization]].<br><br>
To use TreeAttribute, add the using statement for '''Vintagestory.API.Datastructures'''.
 
To use TreeAttribute, add the using statement for '''Vintagestory.API.Datastructures'''.<br><br>
For documentation, see [http://apidocs.vintagestory.at/api/Vintagestory.API.Datastructures.TreeAttribute.html TreeAttribute] and [http://apidocs.vintagestory.at/api/Vintagestory.API.Datastructures.ITreeAttribute.html ITreeAttribute].
== 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.<br>
Within the API, TreeAttribute is often employed to store persistent entity data, and to access data extracted from JSON files.<br>

Revision as of 08:38, 14 April 2020

TreeAttribute

Tree attribute is a nested data structure.
TreeAttribute 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 data serialization.

To use TreeAttribute, add the using statement for Vintagestory.API.Datastructures.

For documentation, see TreeAttribute and ITreeAttribute.

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.

Example in code

using Vintagestory.API.Datastructures;

class Example
{
    Example()
    {
        // Setting and getting values
        TreeAttribute tree;
        tree = new TreeAttribute();

        float someValue = 0.35f;
        string someKey = "valueKey";

        // Set the value
        tree.SetFloat(someKey, someValue);
        // Retrieve the value
        tree.GetFloat(someKey);
    }
}