PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Jul 02 2018, 4:27 PM PST 2 min

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 in Studio to see a list of all of the enums.

Methods

Enums have a single method:

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

The Enum object has a single method:

Method Description
GetEnums() Returns a table of all the Enums.

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.

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

Outputs:

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.

To set the RightSurface property in the BasePart class to Enum.SurfaceType.Weld:

game.Workspace.Part.RightSurface = Enum.SurfaceType.Weld
game.Workspace.Part.RightSurface = 2 -- setting it with the id of the enum value
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 three properties:

Property Description Notes
Name The name of the EnumItem object "Read-Only"
Value The id of the EnumItem for a specific Enum "Read-Only"
Enum EnumType The parent Enum that the EnumItem is within "Read-Only"
Tags:
  • coding
  • concept
  • lua