Modding:TreeAttribute: Difference between revisions

From Vintage Story Wiki
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 [[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, 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>


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>

Revision as of 09:07, 14 April 2020

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.

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

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);
    }
}

For documentation, see TreeAttribute and ITreeAttribute.