How do I…
Save a (massive) array variable to the deveice, and call it back as an array.
I know that you can store texts and numbers, and there may be a way to do so with the ToJSON() and the parse JSON and store in variable action, but i am unsure,
This would use 3 buttons and the scene variable string named temp.
It saves the array Players to Options in Game Storage.
(You can use whatever you want for the storage names)
I set temp to “” because you said the array was large. If temp wasn’t needed anymore, it might as well be set to "nothing.
This is the save. It’s a mix of save text to storage and ToJSON
1 Like
ah, ok, thanks!
I though this might be the answer, as i saw it worked for a structure variable on youtube.
Yes, it works for structures and arrays. To save it converts the variable to a JSON string and then saves the string to storage. To load it loads the string that’s in JSON into a string, and converts the string to a variable.
1 Like
hmm, for some reason it will only call back one number child with the value of zero. Any ideas?
my events:
and for some reason events reference a scene variable with the same name as the global array, but i cant find it
ahHA!!
found it.
the ToJSON() thing wants a scene variable, despite me wanting a global variable, i just need a temporary varible, and ill be all set, thanks!
1 Like
I’m glad it’s working. I thought I’d share my example. There are some concepts that I don’t have memorized. So, I usually make a test project. I played with it afterwards. It demonstrates using an array of structures. I think it would be much easier. You can add as many children as you like. The basic concept is that you build a structure and then add it to the array.
Try me: Objects are draggable, right click toggles the animation.
source: (click the green [code] and [download zip])
sorry to bring this up again, but how do i convert an array to JSon now? i can’t find that expression
The variable system has been merged and simplified since this post. It’s now a unified ToJSON(variableName). It will work regardless of the variable type.
You can type ToJSON and use the autocomplete
JsonString is a string and List is an array.
Or using the expression builder
This is if you were saving it into a sting, it would work similar if you were saving it to storage.
I guess it’s just the variable part that changed. You now use just the variable name instead of VariableString()
Tomorrow, I might update the screenshot if I remember. It’s late here.
This is from a recent example. It used a save and load button and displayed the array in a text object after loading it from storage. It used the split function from the array tools extension to create the array.
2 Likes
Thank you,
you earn my respect
edit: can you also help me with my inventory system problem?
1 Like
If you didn’t already, just start a new thread. Im here often and help when I can. There are others as well.