0 votes

Trying to be able to toggle between modes with this button so that I can change it's details (including which shortcut triggers it) depending on mode but it's currently not working. I can set any details I want to in the mode function but the game is ignoring my attempts to set a button short cut.

onready var button_1 = TextureButton.new()

func set_button_mode( mode: int ) -> void :
    #combat mode
    if mode == 0 :
        var button_key = InputEventKey.new()
        button_key.set_scancode(KEY_Q)
        button_1.set_shortcut( button_key )


func _ready() -> void:
    set_button_mode(0)

Also I notice that when I set the key with the editor, it shows in the the tool tip. Does any one know if this behavior is automatic or if I need to manually set this with GDScript if I change it latter?

Godot version v3.5.1
in Engine by (43 points)

I found a way. if I build a shortcut in the editor, then save it, Then clear the short cut in the editor, I can load the saved file it into my button. It works but I'm not sure what the difference is??? I wish the documentation was clearer...

func set_button_mode( mode: int ) -> void :
#combat mode
if mode == 0 :
    button_1.set_shortcut(load("res://UI/ButtonShortcuts/Q_KEY.tres"))

1 Answer

0 votes

I ended up attaching a script to my buttons to make it work.

In my button manager node I did this:

func set_button_mode( mode: int ) -> void :
    #combat mode
    if mode == 0 :
        button_1.set_skill_shortcut(KEY_Q)

Then in the button script I created a method that would set the short cut:

func set_skill_shortcut( scancode : int) -> void :
        var button_shortcut : ShortCut = ShortCut.new()
        var button_event : InputEventKey = InputEventKey.new()
        button_event.scancode = scancode
        button_shortcut.set_shortcut(button_event)
        self.set_shortcut(button_shortcut)

Seems odd that you have to create a shortcut inside the short cut... Yo dog, heard you liked short cuts...
Any who, it worked!

by (43 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.