Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Tentamens |
Hello there!
Okay hang with me this is very confusing, I’m trying to save the high score of my game and the “spending score” (which is just the past score you got added on to each other) but I am having issues saving these both to the same file (stick with me) but when I do it adds the “spending score” as it should but it also does the same thing with the high score, I checked my code to make sure it’s not doing anything to add
How do I know it’s not me being an idiot (hopefully) in my code.
I tried saving them both to a different files and it worked! (sort of) high score wasn’t getting added it was keeping the high score and “spending score” was being added onto itself,
But whenever I close Godot and reopen it “spending score” gets wiped but high score stays.
here’s my code -
spending score -
func save_spend_score():
print("saving spending score")
var save_dat = File.new()
save_dat.open(SAVE_FILES_PATH, File.WRITE_READ)
save_dat.store_var(spending_score)
save_dat.close()
func load_spend_score():
var file = File.new()
if file.file_exists(SAVE_FILE_PATH):
file.open(SAVE_FILES_PATH, File.READ)
spending_score = file.get_var(spending_score)
print("this is the spending score ", spending_score)
file.close()
high score -
func save_highscore():
var save_data = File.new()
save_data.open(SAVE_FILE_PATH, File.WRITE_READ)
save_data.store_var(highscore)
save_data.close()
func load_highscore():
var save_data = File.new()
if save_data.file_exists(SAVE_FILE_PATH):
save_data.open(SAVE_FILE_PATH, File.READ)
highscore = save_data.get_var(highscore)
print("this is highscore ", highscore)
save_data.close()
forgive me for the code being spaced weird the code sample was being weird and only let me put the code in like that
If you can help me on this HUGE thanks!