Level advance isn't working?

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

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)

extends Node

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

func _process(delta):
	if targetObjectsPoints >= 5:

func _level_switch():
    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.

:bust_in_silhouette: Reply From: Inces

I am guessing the code is not triggering setter, because :
var level = Playerdata.level - is a reference, not a viariable itself.

func _level_switch():
Playerdata.level += 1

That tiny change should repair stuff

Wow that did the trick!! Thank you!

miss_bisque | 2021-02-23 22:58