Start button signals not working in "dodge the creeps" tutorial.

Godot Version

Godot 4

Question

I’m trying to manually code my signals in the “dodge the creeps” tutorial to make sure that I understand how they work, but when I press the start button nothing happens. I’ve read and reread the documentation and many tutorials, but I still don’t know what I’m doing wrong.

I’m trying to connect the ‘pressed’ signal from the start button to the ‘_on_start_button_pressed()’ function in hud.gd, and then connect hud.gd’s ‘start_game’ signal to
the ‘new_game()’ function in main.gd. I’ve included hud.gd and main.gd below. Sorry if I’ve omitted any necessary info.

extends CanvasLayer


signal start_game


func func_ready() -> void:
	$startbutton.pressed.connect(_on_start_button_pressed)
	$messagetimer.timeout.connect(_on_message_timer_timeout)


func show_message(text):
	$message.text = text
	$message.show()
	$messagetimer.start()


func show_game_over():
	show_message("Game Over")
	await $messagetimer.timeout
	
	$message.text = "Dodge the Creeps!"
	$message.show()
	
	await get_tree().create_timer(1.0).timeout
	$startbutton.show()
	
func update_score(score):
	$scorelabel.text = str(score)


func _on_start_button_pressed():
	$startbutton.hide()
	start_game.emit()


func _on_message_timer_timeout():
	$message.hide()

main.gd:

extends Node


@export var mob_scene: PackedScene
var score


func game_over():
	$scoretimer.stop()
	$mobtimer.stop()
	$hud.show_game_over()
	


func new_game():
	score = 0
	$Player.start($startposition.position)
	$starttimer.start()
	$hud.update_score(score)
	$hud.show_message("Get Ready")
	


func _ready() -> void:
	$Player.hit.connect(game_over)
	$mobtimer.timeout.connect(_on_mob_timer_timeout)
	$scoretimer.timeout.connect(_on_score_timer_timeout)
	$starttimer.timeout.connect(_on_start_timer_timeout)
	$hud.start_game.connect(new_game)
	


func _on_mob_timer_timeout():
	
	var mob = mob_scene.instantiate()
	
	var mob_spawn_location = $mobpath/mobspawnlocation
	mob_spawn_location.progress_ratio = randf()
	
	mob.position = mob_spawn_location.position
	
	var direction = mob_spawn_location.rotation + PI / 2
	
	direction += randf_range(-PI / 4, PI / 4)
	mob.rotation = direction
	
	var velocity = Vector2(randf_range(150.0, 250.0), 0.0)
	mob.linear_velocity = velocity.rotated(direction)
	
	add_child(mob)


func _on_score_timer_timeout():
	score += 1
	$hud.update_score(score)


func _on_start_timer_timeout():
	$mobtimer.start()
	$scoretimer.start()

I think you know what to do with that :slight_smile:

1 Like

Dear god.

1 Like