+1 vote

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.

in Engine by (13 points)
edited by

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.

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.

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

1 Answer

0 votes

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.

by (14 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.