Problem with Dodge The Creeps tutorial game, mobs keep moving and score timer doesn't stop.

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

I have completed most of the dodge the creeps game, to the point where it is playable. However, there are two problems. First of all, the creeps don’t play their animation and stay the same, even though i put in all of the frames for all the animations. Secondly, when i die the creeps keep spawning and the score keeps counting. I suspect it is because the Game_Over function in Main doesn’t get called since it controls both those things when it triggers, but idk where the problem could be. Here is the main code if it helps:

extends Node

export (PackedScene) var Mob
var score

func _ready():
	randomize()

func new_game():
	score = 0;
	$Player.start($StartPosition.position)
	$StartTimer.start()
	$HUD.show_message("Get Ready")
	$HUD.update_score(score)

func _on_StartTimer_timeout():
	$MobTimer.start()
	$ScoreTimer.start()
	$HUD.update_score(score)

func Game_Over():
	$ScoreTimer.stop();
	$MobTimer.stop();
	$HUD.Game_Over()

func _on_ScoreTimer_timeout():
	score += 1


func _on_MobTimer_timeout():
	$MobPath/MobSpawnLocation.set_offset(randi())
	var mob = Mob.instance()
	add_child(mob)
	var direction = $MobPath/MobSpawnLocation.rotation+PI/2
	mob.position = $MobPath/MobSpawnLocation.position
	direction += rand_range(-PI/4, PI/4)
	mob.rotation = direction
	mob.set_linear_velocity(Vector2(rand_range(mob.MIN_SPEED, mob.MAX_SPEED), 0).rotated(direction))

edit: i have solved the problem with the animation. I forgot to check the “play” box. I still need help with the second problem. If you need any more information, leave a comment asking for it.

I see you have a HUD method called GameOver() as well as a Main method called GameOver(). Perhaps you are accidentally calling the HUD method when you should be calling the Main method.

Diet Estus | 2018-03-20 20:27

The Game_Over function is triggered whenever the player is hit via a signal. Nothing else connects to it. Even if i lowercase it and redo the connection to it, it still does the same thing.

lincolnpepper | 2018-03-20 20:38

:bust_in_silhouette: Reply From: kidscancode

The Game_Over() function (I would point out here that you’re being inconsistent with your capitalization) is called by the player’s hit signal. It seems you’re not correctly connecting it. When you click connect on the signal and you type in the name of the target method, make sure you’re not using ().

You can also make the connection in code by putting this in the Main.gd’s _ready():

$Player.connect('hit', self, 'Game_Over')

Make sure the spelling/capitalization of the function matches.

I’m pretty sure i’m calling the function correctly since the HUD comes up for it. I’ll try the .connect method though

lincolnpepper | 2018-03-21 19:24

:bust_in_silhouette: Reply From: marioyahuar

Hi,

Maybe is late, but I have the same problem with my game and after a few hours I get the answer.

You have to check the “One Shot” box of start timer you use in the project. I expect this solution works for you.

Greetings!

1 Like