Levels are beaten after the first time played (context below)

godot 4

for some reason every time after you enter a level for the first time the level automatically completes itself (shows win screen and plays win sound) its not a problem with either as the problem existed before the win screen did.
To change levels I use get_tree().change_scene_to_file or get_tree().reload_current_scene() for the restart button



(second script is autoloaded)

Under your process you have an if statement checking if win_played = false then all your win state stuff.

You set it to false in the ready func so yeah, looks to be working as intended. I would have a seperate boolean variable like “level_finished” and set this to true when the player enters an area or your win conditions are met. Then put that into the if statement I mentioned above. You could then use if win played to trigger something else after, like a level change or something.

how would that fix the problem though?

Well as far as I can see your setting your variable to trigger on the very first frame thats processed. You don’t want that. If you have a win conditions, you want to have that met then trigger level end.

The problem is that your if statement for ending the level is being met by your ready function. Does that make more sense?

(also it happened without win_played = true in the ready function) but what im understanding from what your saying is that as soon as the level starts on the first frame it doesn’t detect any other enemies in the area causing the level to complete?

1 Like

Oh interesting, does it happen if you set win_played = true under func _ready?

Maybe put some print() in there to test out what’s actually being called. That might help you understand what’s being called when it should/shouldnt

setting that to false on in the ready function doesn’t change anything, I just added it to see if it would do anything

also I put a print under the if not enemy_area.has_overlapping_areas(): and I found that as soon as the game started the print would run so the enemy area is not detecting anything on the first frame

1 Like

ok update, Im not marking this a solution yet because im not 100% sure but I did this, I made a timer and made a bool called “can_win” that is sset to false by default, if its set to true you can win, it gets set to true when the timer reaches 0

sounds like the enemy_area does not have overlapping areas, can you show that part of your scene? maybe connect to the area_exited signal to better debug this.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.