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 revision
Previous revision
Last revisionBoth sides next revision
data-types [2020/07/07 15:32] maximedata-types [2023/09/14 14:52] – [vec2i] polymorphgames
Line 11: Line 11:
 ---- ----
  
-==== integer ====+==== integer and unsigned integer ====
  
-Integer number+Integer number. Cannot be negative for unsigned integers.
  
 <file lua> <file lua>
Line 45: Line 45:
 <file lua> <file lua>
 local value = "String value" local value = "String value"
 +</file>
 +
 +----
 +
 +==== guid ====
 +
 +GUID are unique identifiers used to reference Assets or Game Objects. It can be interpreted from a string.
 +
 +<file lua>
 +local value = "645318b0-021a-4e02-9f91-bd18300e491a"
 </file> </file>
  
Line 57: Line 67:
 local value = { 54, 97 } local value = { 54, 97 }
 </file> </file>
 +
 +[[api:vec2i|Full vec2i api]].
  
 ---- ----
Line 79: Line 91:
 local value = { 19, 86, 45 } local value = { 19, 86, 45 }
 </file> </file>
 +
 +[[api:vec3i|Full vec3i api]].
  
 ---- ----
Line 84: Line 98:
 ==== vec3f ==== ==== vec3f ====
  
-3D float vector+3D float vector.
  
 To initialize a ''vec3f'' with ''x = -15.71'', ''y = -71'' and ''z = 93.03'': To initialize a ''vec3f'' with ''x = -15.71'', ''y = -71'' and ''z = 93.03'':
Line 90: Line 104:
 local value = { -15.71, -71.0, 93.03 } local value = { -15.71, -71.0, 93.03 }
 </file> </file>
 +
 +[[api:vec3f|Full vec3f api]].
  
 ---- ----
Line 103: Line 119:
  
 Quaternion properties can also be set with a ''vec3f'' containing the euler angles in degrees. Quaternion properties can also be set with a ''vec3f'' containing the euler angles in degrees.
 +
 +----
 +
 +==== matrix ====
 +
 +4x4 matrix representing a spatial transformation
 +
 +Matrices can be initialized with an array of 16 float numbers.
 +<file lua>
 +local value = {
 +    1, 0, 0, 0,
 +    0, 1, 0, 0,
 +    0, 0, 1, 0,
 +    0, 0, 0, 1
 +}
 +</file>
 +
 +Matrices can also be initialized with a dictionary containing three fields: ''Position'' (''vec3f''), ''Rotation'' (''quaternion'') and ''Scale'' (''vec3f''). All those fields are optional.
 +
 +<file lua>
 +local value = {
 +    Position = { 0, 0, 0 },
 +    Rotation = { 0, 0, 0 },
 +    Scale = { 1, 1, 1 } 
 +}
 +</file>
  
 ---- ----
Line 161: Line 203:
     GRASS_CLEAR = true     GRASS_CLEAR = true
 } }
 +</file>
 +
 +==== component type ====
 +
 +Type of a component, represented as a string
 +
 +<file lua>
 +local componentType = "COMP_BUILDING_PART"
 +</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>
 +
 +An example of use can be found in the [[example-mods|Example 02 mod]], in the script file ''scripts/component/COMP_ANTENNA.lua''
 +
 +==== 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