Work with Enumerations
mainEnum values are returned as userdata (lightcppobject) rather than strings. They provide metadata about the enumeration they belong to.
Properties:
Label: The textual name (e.g.,"Blood").Value: The numeric value (e.g.,16).EnumName: The name of the enumeration (e.g.,"SurfaceType").
Usage Patterns:
- Comparison: You can compare an enum value against a string label, a numeric value, or another enum object.
- Assignment: You can assign values using a string label, a numeric value, or an enum object.
- Compatibility:
tostring()and JSON serialization convert enums to their string labels. Using an enum as a table key converts it to a string.
local bt = _C().CurrentTemplate.BloodSurfaceType
-- Querying metadata
_D(bt.Label) -- "Blood"
_D(bt.Value) -- 16
_D(bt.EnumName) -- "SurfaceType"
-- Comparisons
_D(bt == "Blood") -- true
_D(bt == 16) -- true
_D(bt == Ext.Enums.SurfaceType.Blood) -- true
-- Assignment
_C().CurrentTemplate.BloodSurfaceType = "Blood"
_C().CurrentTemplate.BloodSurfaceType = 16
_C().CurrentTemplate.BloodSurfaceType = Ext.Enums.SurfaceType.Blood