Hi all,
I'm testing my first ever custom signal.
In this test, I have it working so when I press 1, 2 or 3 on the keyboard, the speed of my bat changes. This works so that's great.
Now I want it so when the speed changes, a signal is emitted. (I believe I have this part correct). When that signal is emitted, a function is called to change the text of a label.
Except it doesn't. Can anyone offer some advice as to what I've done wrong? This is my first custom signal. Thank you.
#script: gameLevel.gd
extends Node
onready var speedLabelL = get_node("/root/gameLevel/HUD/SpeedL")
signal batSpeedChanged
func _ready():
if OS.is_debug_build():
print("debug mode")
if speedLabelL:
print("We have a label")
speedLabelL.connect("batSpeedChanged", self, "updateScoresEtc")
set_process_input(true)
func _input(event):
if OS.is_debug_build():
if Input.is_key_pressed(KEY_1):
changeBatSpeed(0,1)
elif Input.is_key_pressed(KEY_2):
changeBatSpeed(0,2)
elif Input.is_key_pressed(KEY_3):
changeBatSpeed(0,3)
func changeBatSpeed(bat, speed):
if bat == 0: #left bat
game.batSpeedL = speed
elif bat == 1: #right bat
game.batSpeedR = speed
if OS.is_debug_build():
print("Bat speed = ", str(speed), " for bat # ", str(bat))
emit_signal("batSpeedChanged", bat, speed)
func updateScoresEtc(bat, speed):
if OS.is_debug_build():
print("signal should happen with bat", str(bat), " and speed of ", str(speed))
print("This is where we'll change the label text")
Just a note, all the print statements work except for the last one in the updateScoresEtc
function.