Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is it possible to efficiently convert a character (in a string) to an Enum?

Efficiently meaning not having to write code for every single character.

For example;

function findEnum(char)
	--// Code
end

findEnum("a") --// Returns: Enum.KeyCode.A

I can't just use Enum.KeyCode[string.upper(char)], because I also want it to support symbols.


EDIT: I have discovered the function string.byte (converts a string to its ASCII value), and that KeyCodes can be indexed using their byte value - although this does not necessarily work across all platforms. I have not tested yet.


Thank you!

~TDP

2 comments

0

"I also want it to support symbols" I have no idea what you're talking about. You need to be very specific about what your expected input and expected output are. Give examples!

0

The main problem is that '/' does not work, because Enum.KeyCode['/'] does not exist.

1 answer

✓ Accepted answer

No

The input library which Roblox uses for UIS (and the Enums associated) doesn't have IDs which are associated with the actual ASCII character which represents the key. This as been an issue, and has lead to me translating a lot of their keycodes into their sections.

Unfortunately, you will need to build your own list of keys, their names, and their enums.

1 comment

0

RIP ROBLOX lol. Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.