I have a clunky save system in my game that only works at a certain time.
This is what I want to happen:
-Each time an enemy gets destroyed, Add 1 to Baddie Count.
-When the hero dies, save the storage item as the current BaddieCount.
-On loading a new layout(the Main Menu), set BaddieCount to the saved item.
-Continue this loop for each play-through, so that BaddieCount will keep adding, even after the game is closed.
Once BaddieCount reaches 500, a new character will be unlocked.
What is happening:
Everything works as expected, but the LocalStorage doesn't save until I complete a second playthrough.
For example when playing through de-bugmode:
Round 1, I kill 20 enemies, BaddieCount sets to 20. I close game. Baddie count is back to 0.
Open again. Round 1, I kill 20 enemies, BaddieCount sets to 20. Round 2, I kill 10 more enemies, BaddieCount sets to 30. Now If I close the game and open, the BaddieCount will be set to 20, not 30.
It's as if my data is saving one play-through too late. Any ideas on how I can fix this? I have included an image of the relevant code.
Thanks