ASCII codes in lua?

So in C we would just do

if (character == 0x0A) {

}

Where 0x0A is the hex code of the octal address of the ascii unit for enter, that being 10 for the octal. And converting that to hex we get A. We define 0x to say its a constant and not a variable then do 0A instead of just A because our octal range is big

Now I know userinputservice exists and all that but what if the user put in an emoji? We can get the ASCII code for that, sure. But how can we verify it?

Question:

Just compare the input emoji to the emoji in a string?

You could get the numerical code (not via string.byte) for the character and compare it to a stored numeric value corresponding to the emoji in the character set as well if you want.

That or clarify what you want to do.

There are no emoji KeyCode Enums so UserInputService isn’t really relevant to that. ASCII also doesn’t encode emojis, you’ll want utf8/Unicode for that.

What are you trying to achieve? Knowing that makes it a lot easier to help you.

If you’re trying to see which emojis a player has typed in a text box, you can inspect the Text property and it’ll just be a string containing that emoji.

EDIT: If you’re trying to convert numbers to chars you can use string.char for ASCII or utf8.char for Unicode. string.byte and utf8.codepoint do the opposite. E.g.

print(utf8.char(128512)) => 😀
print(string.char(90)) => Z
1 Like