In my game, I would like to display a few random story sentences that will be displayed after [x] levels.
So far, I created a JSON file for all my sentences that will populate my ArrayStory.
When the conditions are met, I randomly choose a RandomIndex from my ArrayStory to pick a sentence and then I delete this index, to make sure the Player won't see it again.
The problem is:
I generate my array on start of the level from the JSON and obviously, it fills the array with all sentences.
So, how can I load the JSON file only once and populate my array and then, each time a randomindex is chosen and deletes the index from the array, it saves the array?
I have an idea that I would like to share with you:
If I create a variable: ArrayStoryFilled = 0
Then, when I load the JSON file into my ArrayStory the first time it sets ArraStoryFilled=1.
When ArraStoryFilled=1, I save this variable in LocalStorage.
Can I save an array in LocalStorage?
then each time a new sentence is picked and deleted from the array, I save the array.
Does localStorage work also on mobile?
Does it sound like a good approach?
it's the first time for me that I tackle save and load system.