0 votes

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.

Godot version 3.2.3
in Engine by (45 points)
edited by

1 Answer

0 votes

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

func levelswitch():
Playerdata.level += 1

That tiny change should repair stuff

by (7,305 points)

Wow that did the trick!! Thank you!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.