The above blueprint is in the playerBP and fires once the actor dies. It “works” in that it saves the current score as highscore and the highscore is loaded on the next run.
It does not work however as even when current score is lower than high score it saves current score as high score.
I don’t see what is wrong here as it should be checking that the current score is higher?
You fires that “script” every the actor dies? Because every the system will create a new SaveGameObject, so when you cast to saveHighScore i think it will be always the default value.
Yes - when you die and end the level it triggers.
So it would be better/right to create a savegame at the start of the game opening (if no savegame exists) then simply cast to savehighscore each death?
Yes, you should create only one savegame at the begin of the game and then, every the player dies, using the cast, you check if the score is greater than the score saved.
Because if you create a new save game everytimes the “high score” value will be set to default value, and every the new score will be higher than 0, so he will write that value.
You should just create one savegame file at the begin and then, when the game start, you control if the savegame already exists. You save the value of the savegame into a var, then during your game you use that var for a cast, and modify every value into the savegame, and when you want to save those changes you have to use the node called “savegame to slot”.
I can create an example if you need
But I am with TAM. Why would the branch not stop it being written?
Even with the branch? Good to know.
So if you make a Savefile the first the games plays, you never make one again or do you create one every the game loads?
So when you load a second, third etc, would you use a Is Valid to make sure you do not over right by mistake?
Sorry, have not done Save Game yet, and chugging Tam’s post.
When you load your savegame through the “Load savegame from slot” you should set the var “savegame” with the value that this node return, and then yes, you can check if is valid, but should be if the savefile exist.
And when you have to modify a value you just pin out that var and use a cast