The "start" button for my 2D "Dodge the Creeps" game doesn't work and text won't go away.

Godot Version

4.6.2

Question

I followed the instructions to the letter, but the start button isn’t functional and the texts “Dodge the Creeps!” & “Get Ready” don’t disappear. All 3 stay on screen depending on if I either put in ‘new_game()’ or ‘pass’ underneath ‘func _ready():’ in ‘main’, with “Get Ready” appearing with ‘new_game’()’ & “Dodge the Creeps” w/ ‘pass’. Everything else works fine, except for what I just mentioned. I’ve tried looking through the documentation again & again, and I just don’t know what I’m doing wrong.

Here’s my ‘main.gd’, followed by my ‘HUD.gd’.

extends Node

@export var mob_scene: PackedScene
var score

func game_over():
	$ScoreTimer.stop()
	$MobTimer.stop()
	$HUD.show_game_over()
	$Music.stop()
	$DeathSound.play()

func new_game():
	score = 0
	$Player.start($StartPosition.position)
	$StartTimer.start()
	$HUD.update_score(score)
	$HUD.show_message("Get Ready")
	get_tree().call_group("mobs", "queue_free")
	$Music.play()

func _ready():
	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()

hud.gd

extends CanvasLayer

signal start_game

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()

In your “main” scene, can you check if the instantiated “hud” scene, if new_game() is connected to start_game()?

something like:

in your “main.gd” script, check if the func "new_game()” has a green connection icon next to it, like in the pic

1 Like

Thanks! I’ll check it out when I wake up.

new_game() is indeed connected to start_game() in the “main” scene.

Can you check the “$StartButton” properties in the Inspector, is “disabled” property on?
The code also looks fine as well, also the same as when I did this.

1 Like

“Disabled” in “StartButton” has no checkmark, and out of curiosity I activated it. It changed nothing.

in ‘main.gd’, with “Dodge the Creeps” with ‘pass’ in func _ready():

when you click the button, does it disappear, or it just remains there?

1 Like

Stick a print statement in here (or breakpoint) to see if it is actually getting so far:

func _on_start_button_pressed():
    print("start button is pressed")
	$StartButton.hide()

and then:

func new_game():
    print("new_game() entered")
	score = 0
2 Likes

I typed in what you said, and nothing changed. And yes, I clicked the “start” button multiple times and got no change,

From Google: A container node inside the CanvasLayer may be blocking input.

Solution: Ensure that your button is below the container in the scene tree (lower in the list = drawn on top) or ensure the parent containers are set to Mouse > Filter = Ignore.

Sometimes mouse inputs get blocked by layers of controls above the button. Since you said you didn’t get a print message, your button likely not being “clicked” because of layers blocking it.

Hope this helps!

1 Like

I don’t see any containers, even with the Godot Documentation to guide me on what they look like.

After thinking about this for a moment, I realized that I’ve been getting really tripped up about the Documentation warning about remembering to remove the call to “new_game()” from “_ready():”. But without the “new_game()” and replacing it with “pass” the player doesn’t appear and the “start” button doesn’t work.

can you show a pic of your scenetree in the “main” scene? something like this:

also is func “_on_start_button_pressed()” connected? (green icon next to it)

1 Like

It is not a change that you are looking for.
Print statements are used in debugging because if the logic flow gets to a print line, that print will certainly execute.
So what you are looking for is console output.
Bottom of the editor is where Godot prints output:

If nothing at all is being printed then _on_start_button_pressed() is not connected.
If so then you will need to select the button in the editor, select "Signals" in the inspector (top right) and click on the pressed to add a connection.
You can also connect by code, but the tutorial is telling you to do this through the editor.
This is the step you likely missed.

2 Likes

So it seems like the problem is that my “func on_start_button_pressed():” wasn’t connected!

1 Like

the same goes as well for the message timer, it should like this whenever a signal is connected:

1 Like

IT’S WORKING! Thank you all for helping me out!

1 Like