How do i set one local storage key to be the same value as another one ?

0 favourites
  • 13 posts
From the Asset Store
Random Maze Generator with Door & Key System - tutorial capx
  • I tried doing this :

    It didn't work out , i got these values :

    I can't think of any other way to do this . Any help ? Thanks in advance .

  • Works for me. Try 'System: Wait for previous actions' to complete before 'LocalStorage: Get item "a"'. Maybe it's a timing problem.

  • 'Set item' doesn't finish until 'On item set' triggers. If you 'Set item' then 'Get item' without waiting for the set to finish, it will likely get the existing value of the item before 'Set item' is done.

    The new 'Wait for previous actions to complete' system action makes this a lot easier in the latest release - all you need is 'Set item', 'Wait', 'Get item', 'Wait'.

  • Thanks for the response .

    The "Wait for previous actions to complete" doesn't seem to exist for me .

    Here's a print : ( i tried putting the "Wait for previous actions to complete" action in the red box )

    I am running R269 .

  • Oh, you're actually using Construct 2. You posted in the C3 forum. Moving post to C2 forum.

  • Oops . I didn't notice , sorry

  • By putting a 0.1 second wait before the local storage gets the key , it worked . But what i am actually trying to do is more complicated .

    I am creating an RPG where a player can have up to 5 characters , and all of the data of these characters are saved to the local storage .

    If you delete a character , the entire local storage keys should change . For ex :

    If you have 3 characters and you delete your first one , your old second character will now be the first one , and your old third character will now be the second one .

    The data that will change includes all the inventory slots of the characters .

    So , in the example cited before , the now first character would have all of the data of the inventory slots of the old second character , and the now second character would have all of the data of the inventory slots of the old third character .

    To do this , i am doing a loop that repeats 24 times ( amount of inventory slots ) , but it's not working . The keys are not changing at all .

    PS : All the keys are already saved , so all the keys that are being get from the event already exist .

    Here are 2 prints ( these represent all the data that needs to be changed if the player just deleted his first character ) :

    I don't expect anyone to come up with a solution immediately , since this is really hard for me to explain and also for someone not involved in the project to understand .

  • By putting a 0.1 second wait before the local storage gets the key , it worked .

    You shouldn't do that, because it will still break if 'Set item' takes longer than 0.1 seconds. You need to use the 'On item set' trigger instead.

  • Sometimes it bugs out and says that a trigger event cannot be inside of a loop .

  • That's because it doesn't make sense to put a trigger in a loop. You need to structure the events differently.

  • After some testing , i can say that this problem is occurring because there is no time for the system to get the keys , and also because i am not very good at loops in Construct 2 .

    This pic below demonstrates a test i tried to make.

    What i want the loop to do , is to wait one second , set the text to the loopindex , and then repeat 23 more times . So the text should be :

    0 - ( 1s pause ) - 1 - ( 1s pause ) - 2 - ( 1s pause ) - 3 ( 1s pause ) - 4 ( 1s pause ) - 5 , etc ..

    Instead , there is just a 1s pause at the begginning of the layout and the text is set to -1 ( indicating the loop is over ) .

    Basically , the loop is just repeating 24 times in the first second of the layout , and completely disregards the 1s wait action .

  • That's how it's meant to work in a loop. See How to use the system 'Wait' action. If 'Wait' completely suspended all your events, it wouldn't be very useful.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you all so much , i was able to fix the problem . I simply remade the system using 3D arrays . It's much easier that way , and it's working really well .

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