Skip to content

Commit 5012ec9

Browse files
gaymeowingIgnisRBX
andauthored
Remove Enum from Luau Reference section (#1250)
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]>
1 parent 5f0acfe commit 5012ec9

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

content/en-us/luau/enums.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ title: Enums
33
description: A fixed list of items (enumeration).
44
---
55

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+
<Alert severity="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>
79

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).
911

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

1216
```lua
1317
local partTypes = Enum.PartType:GetEnumItems()
18+
1419
for index, enumItem in partTypes do
1520
print(enumItem)
1621
end
@@ -19,39 +24,36 @@ end
1924
Enum.PartType.Ball
2025
Enum.PartType.Block
2126
Enum.PartType.Cylinder
27+
Enum.PartType.Wedge
28+
Enum.PartType.CornerWedge
2229
]]
2330
```
2431

2532
## Data type
2633

2734
The `Datatype.EnumItem` is the data type for items in enums. An `Datatype.EnumItem` has three properties:
2835

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`.
3239

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

3542
```lua
36-
-- Properties of the EnumItem called Enum.PartType.Cylinder
37-
print(Enum.PartType.Cylinder.Name) -- Cylinder
38-
print(Enum.PartType.Cylinder.Value) -- 2
39-
print(Enum.PartType.Cylinder.EnumType) -- PartType
43+
print(Enum.PartType.Cylinder.Name) --> "Cylinder"
44+
print(Enum.PartType.Cylinder.Value) --> 2
45+
print(Enum.PartType.Cylinder.EnumType) --> PartType
4046
```
4147

42-
## Assign enum items
43-
44-
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.
4549

4650
```lua
4751
local Workspace = game:GetService("Workspace")
4852

49-
local part = 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+
local part = 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
5557

5658
part.Parent = Workspace
5759
```

0 commit comments

Comments
 (0)