User Tools

Site Tools


data-types

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
data-types [2020/01/23 13:38] – created maximedata-types [2021/06/18 15:46] maxime
Line 146: Line 146:
 | //''_step''// | ''integer'' | Amount of sides of the circle | | //''_step''// | ''integer'' | Amount of sides of the circle |
  
 +----
 +
 +==== bitfield ====
 +
 +A bitfield is a dictionary with enumeration values of a specific type as keys, and boolean values as value.
 +
 +When defining a new object, a enumeration value missing from a bitfield table will be considered as false. When [[:asset-override|overriding existing data]], a missing enumeration value means the existing value will not be overriden.
 +
 +To initialize a bitfield of [[api:building_zone_type|BUILDING_ZONE_TYPE]] with the ''DEFAULT'' and ''GRASS_CLEAR'' values:
 +<file lua>
 +local bitfield = {
 +    DEFAULT = true,
 +    NAVIGABLE = false,
 +    GRASS_CLEAR = true
 +}
 +</file>
 +
 +==== list ====
 +
 +A list is a collection of values of a specific type. This type can be used to create new properties for [[custom-classes|custom classes]]. The following example shows how to declare a ''[[data-types#float|float]]'' list property:
 +
 +<file lua>
 +Properties = {
 +    ...
 +    {
 +        Name = "MyFloatListProperty", -- property name
 +        Type = "list<float>", -- type: list of float numbers
 +        Default = { 1.0, -4.0, 5.0 }, -- default value: list with three float numbers
 +    },
 +    ...
 +}
 +
 +...
 +
 +mod:log(tostring(#myClassInstance.MyFloatListProperty)) -- logs the size of the list
 +mod:log(tostring(myClassInstance.MyFloatListProperty[3])) -- logs the 3rd element of the list
 +</file>
 +
 +==== fixed_sized_array ====
 +
 +A fixed sized array is a list containing a fixed number of values of a specific type. This type of property is specified with it's size (e.g. ''float[5]''), and each value is accessible with the element's index (indexing is 1-based, like everything in lua). The following example shows how to declare and use a [[custom-classes|custom class]] array property containing 4 ''[[data-types#string|strings]]'':
 +
 +<file lua>
 +Properties = {
 +    ...
 +    {
 +        Name = "MyStringArrayProperty", -- property name
 +        Type = "string[4]", -- type: array of 4 strings
 +        Default = { "my", "custom", "default", "values" }, -- default value
 +    },
 +    ...
 +}
 +
 +...
 +
 +mod:log(myClassInstance.MyStringArrayProperty[2]) -- logs the 2nd element of the list
 +</file>
 +
 +==== fixed_sized_map ====
 +
 +A fixed sized map is very similar to a fixed sized array, except it can only take enumeration values as keys. For some properties, a maximum key value can be specified.
 +
 +With a fixed sized map of [[data-types#float|float]] with [[api:building_type|BUILDING_TYPE]] keys, to set the value corresponding to the key ''GENERAL'':
 +
 +<file lua>
 +someType.MyMapProperty[BUILDING_TYPE.GENERAL] = 4.2
 +someType.MyMapProperty["GENERAL"] = 3.4 -- works only with the string version of the enum value
 +</file>
data-types.txt · Last modified: 2023/09/14 14:52 by polymorphgames

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki