Enumeration

From Legacy Roblox Wiki
(Redirected from Enumerator)
Jump to navigationJump to search

An Enumeration, or Enum, is a special data type that can take one of a set of values. For example, the SurfaceType enum is used to select what type of surface a brick has on a certain side, which can take the values "Glue", "Hinge", "Inlet", or a few more. These values act as constants in place of using ambiguous numbers or strings to set a value. You can use the Object Browser to see a list of all of the enums. Additionally, you can see a list of the Enums that have been added to the wiki here.

Methods

Enums have a single method:

Method Description
GetEnumItems() Acts exactly like the GetChildren method and returns a table of all the EnumItems.

Usage

Enums are accessed through a global object called Enum. To get a specific enum, you must index this object. To get one of the EnumItems in a specific enum, you just index that enum.

Example
print(Enum.SurfaceType)
print(Enum.SurfaceType.Weld)

SurfaceType

Enum.SurfaceType.Weld


You can set an enumerated property in a ROBLOX object through Lua in three different ways. It is preferred to set it with the enum object, however.

Example
To set the RightSurface property in BasePart to Weld:
game.Workspace.Part.RightSurface = Enum.SurfaceType.Weld
-- or
game.Workspace.Part.RightSurface = 2 -- setting it with the id of the enum value
-- or
game.Workspace.Part.RightSurface = "Weld" --Setting it with the name of the enum value


EnumItem

The EnumItem object acts as a constant of a specific enum. All members of any enum object are EnumItems.

Properties

The EnumItem object has one known property:

Property Description Notes
string Name The name of the EnumItem object Read-Only