'How do you make a MMO like skill hotbar in Godot?

I want to create a "hotbar" like in MMO or MOBA games where a key press activates a skill.

I found a gdscript tutorial but it uses clicks and not key presses. I tried changing the code to check for when "K" is pressed with if Input.is_key_pressed(KEY_K):, but that didn't work.

Here is the error:

E 0:00:40.192   emit_signal: Error calling method from signal 'pressed': 'TextureButton(AbilityButton.gd)::_on_key_pressed':
Method expected 1 arguments, but called with 0..<C++ Source>  core/object.cpp:1228 @ emit_signal()

I'm new and don't know how to fix the error.

Here's the link to the tutorial: https://kidscancode.org/godot_recipes/ui/cooldown_button/

Here's the original code:

extends TextureButton

onready var time_label = $Counter/Value

export var cooldown = 1.0


func _ready():
    print_tree_pretty()
    time_label.hide()
    $Sweep.value = 0
    $Sweep.texture_progress = texture_normal
    $Timer.wait_time = cooldown
    set_process(false)


func _process(delta):
    time_label.text = "%3.1f" % $Timer.time_left
    $Sweep.value = int(($Timer.time_left / cooldown) * 100)


func _on_Timer_timeout():
    print("ability ready")
    $Sweep.value = 0
    disabled = false
    time_label.hide()
    set_process(false)


func _on_AbilityButton_pressed():
    disabled = true
    set_process(true)
    $Timer.start()
    time_label.show()


func _on_key_pressed():
    pass

Here's my code:

extends TextureButton

onready var time_label = $Counter/Value

export var cooldown = 1.0


func _ready():
    print_tree_pretty()
    time_label.hide()
    $Sweep.value = 0
    $Sweep.texture_progress = texture_normal
    $Timer.wait_time = cooldown
    set_process(false)


func _process(delta):
    time_label.text = "%3.1f" % $Timer.time_left
    $Sweep.value = int(($Timer.time_left / cooldown) * 100)


func _on_Timer_timeout():
    print("ability ready")
    $Sweep.value = 0
    disabled = false
    time_label.hide()
    set_process(false)


func _on_key_pressed(event):
    if Input.is_key_pressed(KEY_K):
        disabled = true
        set_process(true)
        $Timer.start()
        time_label.show()


func _on_AbilityButton_pressed():
    pass


Solution 1:[1]

The error message says it all : Method expected 1 arguments, but called with 0.

That means that the method bound to the signal is defined with one argument, but the signal sends 0 arguments and the engine yells.

You can check the amount of arguments that the signal sends (0) in the BaseButton doc.

Try removing the event :

func _on_key_pressed(event): ? func _on_key_pressed():

Good luck!

Solution 2:[2]

I found a way to make it the key. If you are using a player attach it to the camera and use the Input.is_action_pressed function it should work cause it just worked for me. but make sure you call the node before the variables so the input will be read by the UI system

if Input.is_action_just_pressed("your input") && $../AbilityButton.disabled == false:

$../AbilityButton._on_AbilityButton_pressed()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 LaGoutte
Solution 2 FortyTwo