Hello DevForum,
I’m interested in learning how you can compare the value of an enum and the enum value of that enum category. Here’s what I’m trying to do:
- My Inventory System needs to work by using the inventory slot number and convert it to an enum value for comparison against a InputObject Keycode Enum. This is how I’m achieving that (summary):
KeyCodeEnumValue = Slot Number + 48
(for example, slot 1 would now have the enum value 49 which is the enum value for Enum.KeyCode.One)
The Developer Hub doesn’t seem to explore the possibility of performing the following:
CorrectKeyCode = (KeycodeEnumValue == Enum.KeyCode.One)
I would like to know if there’s any way to compare an Enum Name with an Enum Value. If what I’m saying is a bit confusing, look at the table here.
My current code is as follows:
local CorrectKeybind = (InputObject.KeyCode == KeybindKeyCodeValue)
However, since InputObject.KeyCode = Enum.KeyCode.One
and KeybindKeyCodeValue = 49
, I’m not too sure how to approach this issue. I’d rather not convert numbers into full names of digits, because that’s just inelegant.