User Tools

Site Tools


data-types

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
data-types [2020/07/07 15:32] maximedata-types [2021/06/18 15:46] maxime
Line 161: Line 161:
     GRASS_CLEAR = true     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> </file>
data-types.txt · Last modified: 2023/09/14 14:52 by polymorphgames

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki