Global Variables help

I’m trying to create a bonus system for my game and I want the player to be able to see how many bonus items they’ve collected at the end, but the global variable I’m trying to use doesn’t account for level restarts and it’s messing up the number at the end. Is there a way for me to have the global variable return to its initial value if a level is restarted? Is there a better way for me to approach this?

1 Like

To me it sounds like you have a Global that goes up by 1 when you collect something, but if you die, the Global value remains the same, so the next time you pick it up it’ll go up by 1 again (1 → 2).

What I would recommend is this.
When you start a level, check what the Global value is at. When the character dies (or whatever causes the level to restart), set the Global to that value you got at the start of the level.

I would use a number block to count up and then add it to the global (+ input) once the level is completed. This way it will only update once you finish a level.

Also for reference on how data is kept.

  • Save behavior is saved in browser cache, so the number is saved on reload. It can be reset by clearing cache.
  • Global behavior is kept only on the game session, reloading will reset the global.
  • Number blocks reset by level/object, once you delete an object or change levels, that number is reset (per object)