How to convert a Key enum to a string?

Godot Version

4.2.1

Question

Hello!

I’m trying to create a mechanic where (basically) the script chooses a random keyboard key from a list, displays the key, as a string, to the Player, and the player must press it. I’m making the list as a hardcoded array like so

var choose_from = [KEY_A, KEY_B, KEY_C]

The RNG chooses one, and then I’m stumped. How do I convert this number back into the correct string? I have a few suspicions, but I’m betting there is something super-easy that I just can’t seem to find with Google. Any help is greatly appreciated!

EDIT: Gonna be trying to re-work this with this bad boy here, but if anyone knows something better, still much appreciated :slight_smile:

Yep that’s more or less what I ended up doing - my choose_from array is just string literals now, and I convert in the other direction. It works, thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.