#Creating a level progress system, don't work

9 messages · Page 1 of 1 (latest)

errant mauve
#

This is hard to explain but I am making a 2d platformer. There are 2 levels and I have a basic global variable that contains the player spawnpoint. This worked for the first level, where each time you reached a checkpoint (an area2d) your spawnpoint is updated, and then when you die I reload the scene. But now that I have a second level I created a second spawnpoint variable to store the level2 spawn.

I then made it so when you load into level 1 or 2 it stores what level you are on in a global variable called current_variable. Then in the playerscript in func_ready() there is an if statement that checks the current level and depending on if 1 or 2 it sets self.position = the respective spawnpoint variable.

The death and reloading works fine but when exiting the level and re-entering it seems to get confused. I cant figure out why, using prints I figured out that the game is succesfully noticing what level you are on and the if statement is working. But it doesn't always set you to the right position, but I am pretty sure that the global variables are not being messed with. My greatest suspect is some functionality of the scene loading that I don't understand since I am new to Godot.

#

I just realized that when I load level 2 even without previously loading level 1, I spawn at the level 1 spawnpoint.

#

I am not sure why though

#

I think that the player is checking for the current level before the level has set the global variable current_level.

#

i fixed it..

#

I have a seperate but related issue

#

I have created a Json save and load system for my game

#

I cant get the loaded file to change the global variables.