How do I read local storage data from within a loop?

From the Asset Store
Basic Plugins for Firebase Authentication, Realtime-Database, Cloud Storage
  • I've been trying all day with this without success.

    I am looping through a bunch of items and I want to change their colour depending on their save data. (on or off)

    When the 'For Each' loop runs and iterates through each item it does a Get Item based on the instance item i am at in the index( eg "Profile_"&ProfileButton.ID&"_has_data")

    The issue is that the data takes a little while to come through so it cant be in the loop itself.

    The 'On item' event which is ready to receive this is outside of the loop and therefore seems to be no way of referencing the looped item.

    eg this never triggers if I add a count variable to my loop which counts up with each iteration:

    + LocalStorage: On item "Profile_"&count&"_has_data" get

    This seems like it 'should' be very simple to do but I just cant figure it out.

    :( Help

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can try "Local Storage On any item get". Inside this event extract the ID, for example with the tokenat expression:

    Set id to int(tokenat(LocalStorage.Key, 1, "_"))

    And then pick the object instance with this ID.

    I don't know if this event will be triggered for each key separately though.. You will need to test.

    Alternatively, you can put all values into an array and save the entire array in LocalStorage as one key.

  • Thanks Dop, I think I'm going to put all the save data into an array or dictionary during the loop and then just write the whole thing to local storage once the looping is done.

    I only avoided doing that because it sounded more complicated than just saving individual values, but having endured the pain of trying to save individual values during a loop, it sounds far simpler now (in theory at least).

    It seems that might be the recommended practice for good reason.

    Thanks

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