Save Total Score

I am new in swift and I need little help.
In my game I have high score and total score. I managed to save data for high score but I cant do it for TOTAL SCORE.
I made a function to add score for total score ( totalScore += score) but offcourse every time I restart my game it resets to 0.
What should I do?
Thanks for any help.

Hi @msplajt88,
It seems that when you are saving your score, it is not getting saved OR you are setting it back to zero (initialising it) when you start the game.

If you share some code of what you are doing, you could get some feedback, right now only you are aware of what you are doing and speculating, I would say, you are resetting it at the start with totalScore = 0



@msplajt88 Thanks very much for your question!

I would suggest that perhaps you should save your score using UserDefaults, which will allow you to store your score even after the user closes the app, and then allow the user to retrieve the score when they return to the app. It’s a very handy, and easy feature to use.

I hope this helps!

All the best!

@msplajt88 has not mentioned the way to persist the score, but has instead indicated that the score resets at start. So, even if the developer was using UserDefaults to persist, if the logic reset the score (assigned it to zero at start) then there isn’t much that can be done. I hope that the developer resolved that problem.



This topic was automatically closed after 166 days. New replies are no longer allowed.