Godot Version
Godot 4.2
Question
I’m working through a tutorial for creating an ability hotkey bar for an rpg. However, the tutorial isn’t explaining some things that are confusing me when I try to mess around with it. I’ve tried clicking on the terms for the relevant documentation but it hasn’t really been helpful.
In particular, I’d like some help understanding how shortcuts work for buttons. Here is the relevant code snippet:
var change_key = "":
set(value):
change_key = value
key.text = value
shortcut = Shortcut.new()
var input_key = InputEventKey.new()
input_key.keycode = value.unicode_at(0)
shortcut.events = [input_key]
Breaking things down:
-
I don’t quite understand the variable + set(value): syntax. I haven’t seen that up until now. As far as I can tell, the only place value is set is through a regular assignment statement later that’s just
change_key = "1"
-
I don’t understand the shortcut stuff. I for other things I’ve just used the input map in the project settings and checked for those key presses with the strings I had assigned. However, this doesn’t seem to work with this syntax since it seems to need some Unicode value. For single press keyboard inputs I can replicate this by simply providing the character string for the key I want. However, I don’t know how to set this to take mouse inputs or shift key inputs.
-
Is this ultimately equivalent to using if statements to check for key presses in a process like I did for other things? If so, what are the benefits of doing it one way or the other?