Dodge the Creeps doesn't start mob

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sinauzuguel

Hello. I’m starting tutorial, and I have tried two times the Dodge the Creeps project. I have arrived at a point that I’m stuck, and I would like to ask If you can see were the problem is.

I have followed the tutorial instructions several times, I have corrected some errors and tried again. But the problem now is as it follows:

When the text Get Ready appears on the screen it does not start the mob spawning. I keep on that screen moving my character, with the Get Ready sign, so I think the problem is somwhere from HUD to Main scenes, because Player and Mob works correct individually. Maybe the signal that calls mob doesn’t works properly, but I cannot figure why.

Here is my MAIN

extends Node

export (PackedScene) var Mob
var score

func _ready():
	randomize()
	
func _on_MobTimer_timeout():
	# Choose a random location on Path2D.
	$MobPath/MobSpawnLocation.offset = randi()
	# Create a Mob instance and add it to the scene.
	var mob = Mob.instance()
	add_child(mob)
	# Set the mob's direction perpendicular to the path direction.
	var direction = $MobPath/MobSpawnLocation.rotation + PI / 2
	# Set the mob's position to a random location.
	mob.position = $MobPath/MobSpawnLocation.position
	# Add some randomness to the direction.
	direction += rand_range(-PI / 4, PI / 4)
	mob.rotation = direction
	# Set the velocity (speed & direction).
	mob.linear_velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0)
	mob.linear_velocity = mob.linear_velocity.rotated(direction)
	
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 _on_StartTimer_timeout():
	$MobTimer.start()
	$ScoreTimer.start()
	
func _on_ScoreTimer_timeout():
	score += 1
	$HUD.update_score(score)

And here’s my HUD

extends CanvasLayer

signal start_game

func show_message(text):
	$MessageLabel.text = text
	$MessageLabel.show()
	$MessageTimer.start()
	
func show_game_over ():
	show_message("Game Over")
	
	yield ($MessageTimer, "timeout")
	
	$MessageLabel.text = "Dodge the \nCreeps"
	$MessageTimer.show()
	
	yield(get_tree().create_timer(1), "timeout")
	
	$StartButton.show()

func update_score(score):
	$ScoreLabel.text = str(score)
	
func _on_StartButton_button_down():
	$StartButton.hide()
	emit_signal("start_game")
		
func _onMessageTimer_timeout():
	$MessageLabel.hide()

Thank you very much in advance.

Please format the code in your post to make it more readable. To do that, edit the post, select the “code”, and press the {} button in the editor’s toolbar.

jgodfrey | 2020-05-14 20:49

Hello. I’m starting tutorial, and I have tried two times the Dodge the Creeps project. I have arrived at a point that I’m stuck, and I would like to ask If you can see were the problem is.

I have followed the tutorial instructions several times, I have corrected some errors and tried again. But the problem now is as it follows:

When the text Get Ready appears on the screen it does not start the mob spawning. I keep on that screen moving my character, with the Get Ready sign, so I think the problem is somwhere from HUD to Main scenes, because Player and Mob works correct individually. Maybe the signal that calls mob doesn’t works properly, but I cannot figure why.

Here is my MAIN

extends Node

export (PackedScene) var Mob
var score

func _ready():
	randomize()
	
func _on_MobTimer_timeout():
	# Choose a random location on Path2D.
	$MobPath/MobSpawnLocation.offset = randi()
	# Create a Mob instance and add it to the scene.
	var mob = Mob.instance()
	add_child(mob)
	# Set the mob's direction perpendicular to the path direction.
	var direction = $MobPath/MobSpawnLocation.rotation + PI / 2
	# Set the mob's position to a random location.
	mob.position = $MobPath/MobSpawnLocation.position
	# Add some randomness to the direction.
	direction += rand_range(-PI / 4, PI / 4)
	mob.rotation = direction
	# Set the velocity (speed & direction).
	mob.linear_velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0)
	mob.linear_velocity = mob.linear_velocity.rotated(direction)
	
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 _on_StartTimer_timeout():
	$MobTimer.start()
	$ScoreTimer.start()
	
func _on_ScoreTimer_timeout():
	score += 1
	$HUD.update_score(score)

And here’s my HUD

extends CanvasLayer

signal start_game

func show_message(text):
	$MessageLabel.text = text
	$MessageLabel.show()
	$MessageTimer.start()
	
func show_game_over ():
	show_message("Game Over")
	
	yield ($MessageTimer, "timeout")
	
	$MessageLabel.text = "Dodge the \nCreeps"
	$MessageTimer.show()
	
	yield(get_tree().create_timer(1), "timeout")
	
	$StartButton.show()

func update_score(score):
	$ScoreLabel.text = str(score)
	
func _on_StartButton_button_down():
	$StartButton.hide()
	emit_signal("start_game")
		
func _onMessageTimer_timeout():
	$MessageLabel.hide()

Thank you very much in advance.

sinauzuguel | 2020-05-15 17:36

Well after one week I had figure out what happened: lacked timeout connections. Now It works. So I think It has been resolved :wink: Thank You for your patience anyway.

sinauzuguel | 2020-05-22 00:31

:bust_in_silhouette: Reply From: MagiusII

This happened to me as well. My issue turned out to be that I didn’t add the $StartTimer.start() line into the new_game function.