Reload scene but keep data passed into variables at runtime?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

Hi All. How do you keep the data which gets passed into variables during gameplay?
Say you have a level scene in which you collect points. There is a var in the scene’s script that holds your score. Let’s also assume that you get 2 turns on that level and the final score is a summary of both turns (like in ski jumping - you do 2 jumps on the same hill and the points from both get added up). The easiest way to start the 2nd turn is to reload the level at the end but when I do that, the score var gets cleared…

:bust_in_silhouette: Reply From: wahyuadiramadan
    func savedata(hs):
    	var hs_old=load_data()
    	if hs_old<hs:
    		var data={
    			highscore=hs
    		}
    		file.open(savePath,file.WRITE)
    		file.store_line(to_json(data))
    		file.close()
    
    func load_data():
    	if file.file_exists(savePath):
    		file.open(savePath,file.READ)
    		var dict = {}
    		dict=parse_json(file.get_as_text())
    		file.close()
    		highscore = dict["highscore"]
    		print(highscore)
    	else:
    		var data={
    			highscore=0
    		}
    		file.open(savePath,file.WRITE)
    		file.store_line(to_json(data))
    		file.close()
    	return highscore

Have you been try to save your data to json file? Im using this for save and load highest score hope it can help, everytime player get higher score than before new highscore will replace it