(UNFINISHED, THIS IS A DRAFT YALL)
Hello all,
I have developed a simple module that allows you to easily create your own Enums and use them in your development. You can download the file below and view a short documentation.
Feel free to reply with your feedback, I am a 14-year-old developer and this is one of my first resources I have made for the community. I am always looking to improve.
FILE
EnumList.rbxm (4.7 KB)
DOCUMENTATION
Module
The first step to using any module, of course, is to require it. Can’t really access it otherwise.
local EnumList = require(game.ReplicatedStorage.Packages.EnumList);From here, you are given a few simple functions to start creating:
Module methods
EnumList.new
EnumList.new(name: string, items: { string }): EnumListThis function creates a new EnumList object.
Thenameparameter is the name of your EnumList- for example, Enum.NormalId’s name is “NormalId”.
Theitemsparameter is an array of strings that will become your EnumListItems.
EnumList:GetEnumList
EnumList:GetEnumList(name: string): EnumListFetches a previously created EnumList that matches the specified name.
EnumList:GetEnumLists
Syntax:
EnumList:GetEnumLists(): { [string]: EnumList }Returns a dictionary of every single created EnumList where each key is the name of an EnumList, and each value is the corresponding EnumList.
To view more info about each class, open the next category below.
Classes
EnumList
{ "ItemOne": EnumListItem, "ItemTwo": EnumListItem, "ItemThree": EnumListItem ... }An
EnumListobject contains a list of EnumListItems.Properties
None
Methods
EnumList:GetName
EnumList:GetName(): stringReturns the name of the
EnumList.
EnumList:GetEnumItems
EnumList:GetEnumItems(): { EnumListItem }Returns an array containing every one of the EnumListItems inside the
EnumList.
EnumList:GetEnumNames
EnumList:GetEnumNames(): { string }Returns an array containing every one of the EnumListItems’ names inside the
EnumList.
EnumList:FromName
EnumList:FromName(name: string): EnumListItemLooks for an EnumListItem that has
nameas it’s name and returns it.
EnumList:FromValue
EnumList:FromValue(value: number): EnumListItemLooks for an EnumListItem whose numeric value matches
value.
EnumList:Delete
EnumList:Delete(muteWarnings: boolean): TrashedEnumListDeletes all traces of the
EnumList, and returns a copy of it with no methods. (only EnumListItems)
Extra Cases
EnumList(_: string?)@return - if (_ == nil) then EnumList:GetEnumItems() else EnumList[_]
tostring(
EnumList)@return - "EnumList.{ListName}"
EnumListItem
{ "Name": string, "Value": number, "EnumType": string, "Identifier": string }An
EnumListItemobject is a child object to an EnumList.Properties
EnumListItem.Name
A string containing the
EnumListItem’s name.
EnumListItem.Value
A numeric value to make a
EnumListItemunique from others in an EnumList.
EnumListItem.EnumType
A string defining the
EnumListItem’s parent EnumList.
EnumListItem.Identifier
A string defining the path of the
EnumListItem. Formatted asEnumList.{ListName}.{ItemName}({ItemValue}).
Methods
EnumListItem:GetEnumList
EnumList:GetEnumList(): EnumListReturns the
EnumListItem’s parent EnumList.
EnumListItem:IsA
EnumList:IsA(_: string): booleanReturns true if the
EnumListItembelongs to an EnumList with the name_.
Extra Cases
EnumListItem()@return - EnumListItem.Value
tostring(
EnumListItem)@return - "EnumList.{ListName}.{ItemName}"
EnumListItem == Value
@return - EnumListItem.Identifier == Value.Identifier
Examples
Creating a new list
local EnumList = Packages.import("EnumList");
local CarBrand = EnumList.new("CarBrand", {
"Volvo",
"Volkswagen",
"BMW",
"Audi",
"Ford",
});
Retrieving a list from a different script
local CarBrand = EnumList:GetEnumList("CarBrand");
Item comparison
local CarBrand = EnumList:GetEnumList("CarBrand");
local playerA_car = CarBrand.Volvo;
BindableEvent.Event:Connect(function(playerB_car): ()
print(playerA_car == playerB_car)
end);
BindableEvent:Fire(CarBrand.BMW); --> false
BindableEvent:Fire(CarBrand.Ford); --> false
BindableEvent:Fire(CarBrand.Volvo); --> true