Apologize if this is a beginner question, but I am having trouble finding a solution online. Most of the help I could find did not solve my problem and were for a previous version of Swift.
I would like to keep a cumulate score of a player in a game. It would be zero the first time they logged in, but everytime they played it would increase depending on how many rounds they played.
I've tried a few arrangements, but right now in my AppDelegate file I have:
UserDefaults.standard.set(Int(100),forKey:"TotalPoints")
Then, in other parts of the GameScene when the player advances I have:
let defaults=UserDefaults.standard
var CurrentExtras=defaults.integer(forKey: "TotalPoints")
CurrentExtras = CurrentExtras+100
UserDefaults.standard.set(Int(CurrentExtras),forKey:"TotalPoints")
This works for in game updating, but once I close the app and reboot it, then it goes back to the initial value. How do I check the initial Defaults to make sure it is not overwriting one? Am I doing this correct to begin with?