User:Legend26/Test

From Legacy Roblox Wiki
Revision as of 14:00, 7 April 2012 by >JulienDethurens
Jump to navigationJump to search

Enum

An Enumeration, or Enum, is a special data type that consists of a set of values. For example, the SurfaceType enum has different values that are used to select what type of surface a brick has on a certain side. Some of which are "Glue", "Hinge", and "Inlet". 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.

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.RightSurface.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