Skip to content

Enum

Summary

Methods Methods of an `Enum`.

Methods

GetEnumItems()

EnumItem[]

Returns an array of all EnumItem options available for the enum.


FromName(name: string)

EnumItem | nil

Finds an EnumItem by name.


FromValue(value: Number)

EnumItem

Finds an EnumItem by value.


Examples

Use an enum group to look up a named item:

local jumpKey = Enum.KeyCode:FromName("Space")
if jumpKey == Enum.KeyCode.Space then
print("Space is the jump key")
end

An unknown name returns nil, so check user-supplied names before using the result:

local key = Enum.KeyCode:FromName("NotAKey")
if key == nil then
print("Unknown key name")
end

GetEnumItems() is useful when building a list of allowed choices:

for _, material in ipairs(Enum.Material:GetEnumItems()) do
print(material.Name)
end

In Vortex Studio 0.3.8, FromName("R") returned Enum.KeyCode.R and an unknown name returned nil.