If statement being iffy
Asked Answered
S

2

0

I've got an if statement that is not playing ball. This seems really straightforward, but when I run the scene, the if statement never loops. It also doesn't revert to the else statement or throw up any errors. One sad, lonely enemy spawns and wonders why it has no friends. I'm at a loss and would love some help.

func enemy_spawner():
var enemy_spawn_array = spawn_positions.get_children()

if spawn_position_number < 7:
	var enemy_instance = enemy_scene.instantiate()
	get_tree().root.add_child(enemy_instance)
	var spawn_position = enemy_spawn_array[spawn_position_number]
	enemy_instance.position = spawn_position.position
	spawn_position_number += 1
else:
	spawn_position_number = 0
	$SpawnTimer.start()
Shouse answered 23/11, 2023 at 8:31 Comment(0)
C
1

If statements don't loop. Your problem description is a bit vague. But if I had to guess the problem is that the enemy_spawner function isn't called anymore after the first time. Are you calling it from the SpawnTimer signal? If yes, that is the issue because the start function will never be called (because it is party of the else branch).

If that is not your issue you will have to provide a bit more code.

Copyboy answered 23/11, 2023 at 8:51 Comment(0)
S
0

Copyboy

You nailed it! I had the if statement as part of a loop in a previous iteration, removed the loop, and then forgot. Let's just not think about the time I wasted trying to figure this out. Thanks for the help!

Shouse answered 23/11, 2023 at 8:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.