In my game, I have flying objects (fruit ninja style) with various levels. When a player reaches a certain score
var = targetObjectsPoints, the code switches scenes to a level switch scene which is basically just a control node letting them know that they have advanced to the next level. Then their score is reset and they are sent back to the game after presseing start. Even thought I have my
level informaton in an autoloaded script called
PlayerData.gd, my game is still not advancing the level.
In the autoloaded
PlayerData.gd I have the following code (simplified here for brevity)
var level = 1 setget set_level
func set_level(value: int) -> void:
level = value
Then in my
Game script, there is the
_process(delta): and my
_level_switch() function that handles advancing a level
var level = PlayerData.level
if targetObjectsPoints >= 5:
level += 1
_reset() # resets player's targetObjectPoints
Then, the level switch scene just tells the player that they're advancing to the next level. They hit start, and should be able to advance to the next level. But after the level switch scene switches back to my main game scene, when i
print(str(level)) in the
_ready(): function, it still says
level = 1 when it should say
level = 2 and do everything it needs to do to function in the 2nd level.
I think there may be a problem when I reset the
targetObjectsPoints variable, becaues the game now thinks the targetObjectsPoints are not enough to advance to the next level. How do I reset the player's
targetObjectsPoints and also have the game keep track of the fact that it still needs to advance to the next level?
and just a note, my different levels do not have separate scenes attached to them. The only thing that changes from level to level in my game is that the objects get smaller. So I just have a conditional that tells my main game script to change the size of the object depending on what the level is. Id like to avoid having different scenes for each level, since only one tiny factor changes, but if that's the best way forward then I guess I can understand.