You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Moved the Enum page to be under the Scripting section instead of Luau
Reference.
Also fixed the luau url on the index page for the scripting Section, and
added a warning about using the `Value` property of EnumItems.
---------
Co-authored-by: IgnisRBX <[email protected]>
Copy file name to clipboardExpand all lines: content/en-us/luau/enums.md
+22-20Lines changed: 22 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,14 +3,19 @@ title: Enums
3
3
description: A fixed list of items (enumeration).
4
4
---
5
5
6
-
The **enumeration** data type, or `Datatype.Enum`, is a fixed list of items. You can access enums through the global object called `Datatype.Enum`. For a full list of Enums and their items, see [Enums](/reference/engine/enums) in the API Reference.
6
+
<Alertseverity="info">
7
+
Enums are not a [built-in Luau type](https://luau.org/typecheck#builtin-types) and they exist only in Roblox, but they're conceptually similar to other Luau data types and are something you'll work with frequently in Roblox development.
8
+
</Alert>
7
9
8
-
## Get enum items
10
+
The **enumeration** data type, or `Datatype.Enum`, is a fixed list of items. You can access enums through the global object called `Datatype.Enum`. For a full list and their respective items, see [Enums](/reference/engine/enums).
9
11
10
-
To get all items of an Enum, call the `GetEnumItems()` method on the enum. The following code sample demonstrates how to call `GetEnumItems()` on the `Enum.PartType` enum.
12
+
## Enum items
13
+
14
+
To get all items of an enum, call the `Datatype.Enum:GetEnumItems()|GetEnumItems()` method on it. The following code sample demonstrates how to call `Datatype.Enum:GetEnumItems()|GetEnumItems()` on the `Enum.PartType` enum.
11
15
12
16
```lua
13
17
localpartTypes=Enum.PartType:GetEnumItems()
18
+
14
19
forindex, enumIteminpartTypesdo
15
20
print(enumItem)
16
21
end
@@ -19,39 +24,36 @@ end
19
24
Enum.PartType.Ball
20
25
Enum.PartType.Block
21
26
Enum.PartType.Cylinder
27
+
Enum.PartType.Wedge
28
+
Enum.PartType.CornerWedge
22
29
]]
23
30
```
24
31
25
32
## Data type
26
33
27
34
The `Datatype.EnumItem` is the data type for items in enums. An `Datatype.EnumItem` has three properties:
28
35
29
-
-`Name`- The name of the `Datatype.EnumItem`.
30
-
-`Value`- The numerical index of the `Datatype.EnumItem`.
31
-
-`EnumType`- The parent `Datatype.Enum` of the `Datatype.EnumItem`.
36
+
-`Name`— The name of the `Datatype.EnumItem`.
37
+
-`Value`— The numerical index of the `Datatype.EnumItem`.
38
+
-`EnumType`— The parent `Datatype.Enum` of the `Datatype.EnumItem`.
32
39
33
-
Some properties of objects can only be items of certain enums. For example, the `Shape` property of a `Class.Part` object is an item of the `Enum.PartType`Enum. The following code sample demonstrates how to print the properties of the `Enum.PartType.Cylinder`EnumItem.
40
+
Some properties of objects can only be items of certain enums. For example, the `Class.Part.Shape|Shape` property of a `Class.Part` object is an item of the `Enum.PartType`enum. The following code sample demonstrates how to print the properties of the `Enum.PartType.Cylinder`enum item.
34
41
35
42
```lua
36
-
-- Properties of the EnumItem called Enum.PartType.Cylinder
To assign an `Datatype.EnumItem` as the value of a property, use the full `Datatype.Enum` declaration. You can also use its `Value` or `EnumType`.
48
+
To assign an `Datatype.EnumItem` as the value of a property, use the full `Datatype.Enum` declaration. You can also use the item's `Datatype.EnumItem.Name|Name` property as a string.
45
49
46
50
```lua
47
51
localWorkspace=game:GetService("Workspace")
48
52
49
-
localpart=Instance.new("Part") -- Create a new part
50
-
part.Shape=Enum.PartType.Cylinder-- By EnumItem (best practice)
51
-
part.Shape=Enum.PartType.Cylinder.Value-- By EnumItem Value
52
-
part.Shape=2-- By EnumItem Value
53
-
part.Shape=Enum.PartType.Cylinder.Name-- By EnumItem Name
54
-
part.Shape="Cylinder" -- By EnumItem Name
53
+
localpart=Instance.new("Part") -- Create a new part
54
+
55
+
part.Shape=Enum.PartType.Cylinder-- By full enum item declaration (best practice)
56
+
part.Shape="Cylinder" -- By enum item's name as a string
0 commit comments