How do I get a persistant dictionary using Containers?

  • Hey!

    I'm trying to have all the NPC's stats stored in their own dictionary, well MULTIPLE dictionaries for different types of stats. So I have a container with the character, and several dictionarys.

    I need these stats to persist through out multiple layouts, so I added persist to the NPC sprite and was hoping because it was in a container that would flow through to the dictionaries.

    Sadly, it does not. The dictionaries get deleted when I move between layouts.

    I know I could just use variables on the sprite... but I have hundreds of values in each dictionary. Plus I want to be able to save and load them using JSON/LocalStorage so dictionaries are perfect.

    The other option I can see is save and load from JSON each time... but that seems... to put it nicely... janky.

    Here's a capX demonstrating this. Run it in debug and you'll see the sprites variable stays with persist, but not the library. https://drive.google.com/open?id=1eLmyy ... lfAIQNLGv5

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Instead of the Persist behavior try setting your player as Global object. Also set Global for all its dictionaries.

    You'll need to remove the player instance from all other layout except the first one.

  • Wow. Thought I'd tested that. Turns out I had ONE thing not set as global in the container (a sprite for collision detection) and once I changed that. Boom. Done.

    Cheers dop2000

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