Topic was automatically imported from the old Question2Answer platform.
Asked By
Suleymanov
How can I store value and recall it after restarting Level? Say, I want to store Best Lap value and recall it when Level is restarted. How would you approach that? I’m new to storing/recalling methods. I’d highly appreciate one variable simple example of the complete procedure.
All I need is to store/replace the value of a variable (eg. BestLap) when a certain condition is met so that the value is preserved and called back after the restart. For instance, if the Best Lap was “3452”, I want it to show “3452” even after the Level restarted.
var save_game = File.new()
save_game.open("user://savegame.save", File.WRITE)
var current_scene_dict = {
"best lap" : best_last_number
}
save_game.store_line(to_json(current_scene_dict))
save_game.close()
Then, to load:
var save_game = File.new()
if not save_game.file_exists("user://savegame.save"):
return
save_game.open("user://savegame.save", File.READ)
var data = parse_json(save_game.get_line())
best_lap_number = data["best lap"]
Highly appreciated, mate! It’s because of kind people like you the beginners like me don’t quit.