Keep same score variable in all scenes

Hello,

my question is, if it is possible to keep a score variable in all of my scenes and increase it or reduce it in my different scripts.

I would suggest to add a script to handle the whole game state.
In this script you can define score and any other variables.

Then add this script to root entity. So, afterwards you can get your score by

this.app.root.script.game.score

1 Like

I think i don’t understand.What do you mean root entity?
In that way i can control my score in each scene and keep my score for the other scenes?

As long as you’re using JS, you can extend any object.

So, just add a score variable in pc.app and you can get it in any scene.

Thank you again.
Is there any example link that i can follow?

Oh, just

this.app.score = 0;
this.app.score++;

That’s all;

@mikefinch How did you do this exactly? I am not getting how you get a variable between scenes.