ประเภทข้อมูลรายการ enumeration หรือ Enum เป็นรายการคงที่คุณสามารถเข้าถึงตัวเลขผ่านวัตถุทั่วโลกที่เรียกว่า Enumสำหรับรายการเต็มของตัวเลขและรายการของพวกเขาดูที่ Enums เอกสารอ้างอิงเกี่ยวกับ API
รับรายการเลขอนุกรม
เพื่อรับรายการทั้งหมดของ Enum โทรไปที่วิธี GetEnumItems() บน enumตัวอย่างโค้ดต่อไปนี้แสดงวิธีการเรียก GetEnumItems() บน enum Enum.PartType
local partTypes = Enum.PartType:GetEnumItems()for index, enumItem in partTypes doprint(enumItem)end--[[Enum.PartType.BallEnum.PartType.BlockEnum.PartType.Cylinder]]
พิมพ์
ประเภทข้อมูล EnumItem คือประเภทข้อมูลสำหรับรายการในเอนเนม คุณสมบัติ EnumItem สาม:
คุณสมบัติบางอย่างของวัตถุสามารถเป็นรายการของ enum บางอย่างเท่านั้นตัวอย่างเช่น คุณสมบัติ Shape ของวัตถุ Part เป็นรายการของ Enum.PartType Enumตัวอย่างโค้ดต่อไปนี้แสดงวิธีการพิมพ์คุณสมบัติของ Enum.PartType.Cylinder EnumItem
-- คุณสมบัติของ EnumItem ที่เรียกว่า Enum.PartType.Cylinderprint(Enum.PartType.Cylinder.Name) -- ทรงกระบอกprint(Enum.PartType.Cylinder.Value) -- 2print(Enum.PartType.Cylinder.EnumType) -- PartType
กำหนดรายการ enum
เพื่อกำหนดค่า EnumItem ให้เป็นค่าของคุณสมบัติ ให้ใช้การประกาศเต็ม Enum คุณยังสามารถใช้ Value หรือ EnumType ของมันได้
local Workspace = game:GetService("Workspace")local part = Instance.new("Part") -- สร้างชิ้นส่วนใหม่part.Shape = Enum.PartType.Cylinder -- โดย EnumItem (ดีที่สุด)part.Shape = Enum.PartType.Cylinder.Value -- โดยมูลค่า EnumItempart.Shape = 2 -- โดยมูลค่า EnumItempart.Shape = Enum.PartType.Cylinder.Name -- โดยชื่อ EnumItempart.Shape = "Cylinder" -- โดยชื่อ EnumItempart.Parent = Workspace