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.
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.
Develop games in your browser. Powerful, performant & highly capable.
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.