How do I get sprites with instance variables, that are on a global layer, to maintain their values?

0 favourites
  • 4 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Hi all,

    I've noticed that my sprites, which are on a global layer, still lose the values that have been set to their instance variables when I switch layouts.

    Is this how construct works by design or am I missing something?

  • This is normal. If you need objects not to be destroyed at the end of layout, you should set these objects as global.

    Note, that if you have a global sprite on a global layer, and you switch to another layout with this layer, you'll end up with two instances of this sprite.

    So you should probably do something like this:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • One thing to remember is, a global layer is not the same thing as a global variable or object.

    Global layers are used to override layers on many layouts so you don't have to recreate something like a HUD on every single layout it is needed. This usage of global doesn't have anything to do with persisting throughout the game. Items in a global layout will be re-instantiated on start of layout.

    Global variables/objects are used to give access to the same variable/object throughout the game runtime. These objects exist in all layouts as a single object so any change made to them is persisted when changing layouts. They are instantiated when the game is run and are not removed until the game ends. A non-global variable/object on the other hand is re-instantiated on start of layout for every layout they are place on and removed from memory (causing them to cease to exist) when the layout ends. If they still exist when the layout ends that is. According to the game engine, these are separate objects.

  • dop2000 InDWrekt Thank you so much for this helpful information. I clearly misunderstood the nature of global layers. I was able to solve my problem because of your wonderful sage-like advice.

    Thank you thank you 1000x thank you!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)