How do I keep next level unlocked?

0 favourites
  • 4 posts
From the Asset Store
Unlock Levels, Worlds & skin plus add coins by watching ads
  • Hello Scirra universe! I have come to you for help with something I feel is extremely simple but I just cannot figure it out.

    I have a project which has multiple levels/level buttons. I have saved this to an array, and saved that array to local storage/asJSON. I have it set up so when I click on a level and play it and exit, the level buttons show the number of stars that was achieved in the level using specific sprites belonging to each level button. When 3 stars are achieved in a single level, the next level unlocks. This is all working correctly... except for the part where the next level stays unlocked when the page is refreshed. The levels that have been played save, and the state of the button is correct, but the only way the next "unlocked" level stays unlocked, is if I go into the level,and act as if I played the level.

    I was hoping that if I attached my file, someone could possibly see where exactly I am going wrong? I have stared at this for so long.. I am close to giving up :(

    https://www.dropbox.com/s/agah0lykpmyd3zq/LevelSelect_save_ExampleHelp.c3p?dl=0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Looks like your save logic the 'set item' action is in a bizarre place inside a loop that is running constantly. You should save only once when the array is complete and that'll minimize the conflict and bugs.

  • like plinky said, the Set Item was in a bad place - that whole group was running every tick - 60 times a second, continuously resetting the buttons... and there were a lot of other bugs and issues.

    you can't know what the MaxLevelWon is until after the array is loaded from local storage.

    the State variable on the LevelSprite was not really necessary since the second column of the array was being used to tracking whether a level was locked or not. So, I simplified things a bit.

    the SaveEvent even sheet wasn't very useful - and definitely not needed on each level layout (so I removed it). Once the array is loaded from local storage, it is global (you don't need to load it again when a level starts). The proper time to save the array to local storage is when a level is complete.

    I made a number of other minor improvements, plus added at button to reset progress (delete the local storage item) for testing purposes...

    https://www.rieperts.com/games/forum/levels.c3p

    I wouldn't say this was extremely simple. Arrays give lots of people trouble, and so does local storage. I have seen tutorials on how to lock and unlock levels that didn't actually work and gave people really bad advice!

  • Yea, it is a mess. I am really struggling with this part, my brain just isn't getting through it very well!

    Let me start by saying, you are my hero! I have, what I am pretty sure, is every post that has ever been made explaining how to save/load, along with every one that shows how to make the level buttons etc. It has burned itself in to my brain so much that I dream about event sheets and level arrays. I wake my husband up talking about Construct in my sleep for goodness sake. Thank you oh so much for taking the time to help me out, you have no idea how much I appreciate it! You are a rock star!

    I am so sorry the project was such a mess. When my brain is a mess, my project is a mess. I confused myself real bad with this one, and am just so grateful to you.

    It would be nice for someone to create a tutorial that shows everything that is incorporated into this file (level buttons, different animations for each button, saving/loading, etc) all in one. Unless I missed one...

    Now that I am done rambling.. Thank you again my friend, you are amazing!

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