Modding:TreeAttribute: Difference between revisions

From Vintage Story Wiki
m
Update to 1.19.3.
m (Nyuhnyash moved page Modding:Tree Attribute to Modding:TreeAttribute without leaving a redirect: Part of translatable page "Modding:Tree Attribute")
m (Update to 1.19.3.)
Line 1: Line 1:
{{GameVersion|1.15}}
{{GameVersion|1.19.3}}
<languages/><translate>
<languages/><translate>
<!--T:1-->
<!--T:1-->
Line 8: Line 8:
Attributes are written and read via keys.  
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'''.
== Use in API == <!--T:3-->
== Use in API == <!--T:3-->
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>
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'''.


== Example in code ==  <!--T:4-->
== Example in code ==  <!--T:4-->
Line 17: Line 17:


<!--T:5-->
<!--T:5-->
class Example
public class TreeAttributeMod : ModSystem
{
    Example()
     {
     {
         // Setting and getting values
         public override void StartServerSide(ICoreServerAPI api)
        TreeAttribute tree;
        {
        tree = new TreeAttribute();
            // Setting and getting values
            TreeAttribute tree;
            tree = new TreeAttribute();


        <!--T:6-->
            float someValue = 0.35f;
float someValue = 0.35f;
            string someKey = "valueKey";
        string someKey = "valueKey";


        <!--T:7-->
            // Set the value
// Set the value
            tree.SetFloat(someKey, someValue);
        tree.SetFloat(someKey, someValue);
            // Retrieve the value
        // Retrieve the value
            tree.GetFloat(someKey);
        tree.GetFloat(someKey);
        }
     }
     }
}
</syntaxhighlight>
</syntaxhighlight>
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].
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].
</translate>
</translate>
{{Navbox/modding|Vintage Story}}
{{Navbox/modding|Vintage Story}}
Confirmedusers
711

edits