Confirmedusers
13,514
edits
Mirotworez (talk | contribs) mNo edit summary |
Mirotworez (talk | contribs) (Marked this version for translation) |
||
Line 1: | Line 1: | ||
{{GameVersion|1.15}} | {{GameVersion|1.15}} | ||
<languages/><translate> | <languages/><translate> | ||
<!--T: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, as well as more complex types like ItemStacks and other TreeAttributes (hence a nested structure). | 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). | ||
<!--T:2--> | |||
Additionally you can store data as <code>byte[]</code> if it is not supported by the TreeAttribute itself (for this you could use <code>Vintagestory.API.Util.SerializerUtil</code>). | Additionally you can store data as <code>byte[]</code> 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. | 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 == <!--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'''.<br> | ||
== Example in code == | == Example in code == <!--T:4--> | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
using Vintagestory.API.Datastructures; | using Vintagestory.API.Datastructures; | ||
<!--T:5--> | |||
class Example | class Example | ||
{ | { | ||
Line 22: | Line 25: | ||
tree = new TreeAttribute(); | tree = new TreeAttribute(); | ||
float someValue = 0.35f; | <!--T:6--> | ||
float someValue = 0.35f; | |||
string someKey = "valueKey"; | string someKey = "valueKey"; | ||
// Set the value | <!--T:7--> | ||
// Set the value | |||
tree.SetFloat(someKey, someValue); | tree.SetFloat(someKey, someValue); | ||
// Retrieve the value | // Retrieve the value |