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