How do I make objects not reset when leaving layout?

0 favourites
  • 5 posts
From the Asset Store
A complete set of graphical user interface (GUI) to build 2D video games. With wood, nature, & jungle theme
  • I have some object sprites that symbolize equipment. They all have a number for which slot they are. "Slot 1" for example is the weapon slot. The weapon is set depending on what "Slot 1" contains (what name a variable has).

    If slot1.name=none set weapon to "none".

    When I pick up a weapon it sets slot1.name to the weapon.name (shortsword).

    Which sets slot1.name=shortsword.

    All these objects are on a global layer and they have persist. Yet they reset to their original state if I leave a layout.

    So each time I leave a layout, slot1.name becomes "none" which is it's default state.

    How can I fix this issue?

    EDIT: I noticed when I went back to a layout I picked up a weapon in, it saved that state. But why does it not bring this state over to another layout?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Try making the slot objects global. Persist is for when you return to the same layout, not going to the next layout.

  • It worked but now I have a new problem. Since the objects are global and belong to a global layer, another object is created when I transition between layouts. So if there are 6 itemslots, they become 12 when I enter a new layout.

    If I move the object to a non global layer it fixes this but I have some other reasons for them to stay on a global layer. Is there no other fix to this? Should I remove the persist behaviour?

    Appreciate the help!

  • Yes you can remove the Persist behaviour. What I think you are describing is an inventory that appears on HUD right so making it global is good for this. I don't think you should use both a global layer and global object. When I look at how a global layer works, it deletes and creates new instances between layouts and you don't want this, probably this method is only good for pure UI display and not objects that have values you want to keep. Global objects keep their same position between layout so should work well.

  • Thank you for the explanation! In that case I will make the layer non global and rework some things. It is better that way.

    Cheers :)

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