Data Tables provides you with a custom resource type that holds a list of data entries. You can then easily query data from this resource in C#.
You define your Data Structure in C# like so:
public class ExampleStruct : RowStruct
{
public string Text { get; set; }
public Dictionary<string, SoundEvent> Sounds { get; set; }
public List<string> Strings { get; set; }
}
When you make a change to your Data Table, those changes will be reflected in-game immediately after you save the file.
Custom Attributes
The [JsonTypeAnnotate] attribute will tell the serializer to also store this property's type, allowing for this property to be properly deserialized later.
Combining the above attribute with the [Instanced] attribute provides you with a dropdown in the editor. You can now select any class that inherits from the property's type.
public class BaseClass {}
public class A : BaseClass
{
public int Integer { get; set; }
}
public class B : BaseClass
{
public bool Boolean { get; set; }
}
public class ExampleStruct : RowStruct
{
[JsonTypeAnnotate, Instanced]
public List<BaseClass> List;
}
Report Issues
If you encounter a bug or you want something added, your options are:
Submit a Bug Report / Feature Request right here on sbox.game