I hope this hasn’t already been answered, but I couldn’t find a thread about this on google. Any links towards those is appreciated!
Hello! I’m trying to create toolbar for my game, and I was wondering if there is a better, cleaner method of converting the numbers 1,2,3 etc. to their respective keyboard keys (i.e. 2 > Enum.KeyCode.Two).
I know that I could store these values in a table and search in it but I was hoping there is a better, preferably cleaner alternative of reaching the same result.
Actually, this is exactly what you should do—store each keycode in a table because enum values can change anytime and should not be directly indexed/played with. (for example, the number that you are using, 48, can change anytime.)
for i = 1,3 do -- 3 = number of buttons
cas:BindAction(tostring(i), handleToolbarSelection, false, Enum.KeyCode[i])
-- Enum.KeyCode[tostring(i)] didn't work either.
end
Errors out as 1 is not a valid member of "Enum.KeyCode"