I made a sample save and load system .
I'm aiming to initial basic state( herohp = 0 ) and load the lastest state of my hero( herohp = 46),but it seem not to work like that .
Can somebody tell me why i only have one variables and output result 2 answers?
output
Game Loaded
herohp: 46
herohp: 0
savegame.txt
[hero]
Lv=0
hp=46
mxhp=100
xp=0
mxxp=100
extends Node
var savegame = File.new()
var file_to_save= "res://savegame.txt"
var heroLv = 0
var herohp = 0
var heromxhp = 0
var heroxp = 0
var heromxxp = 0
func _on_Button_pressed():
if savegame.file_exists(file_to_save):
var configFile= ConfigFile.new()
configFile.load(file_to_save)
var heroLv = configFile.get_value("hero", "Lv")
var herohp = configFile.get_value("hero", "hp")
var heromxhp = configFile.get_value("hero", "mxhp")
var heroxp = configFile.get_value("hero", "xp")
var heromxxp = configFile.get_value("hero", "mxxp")
print ("Game Loaded")
print ("herohp: ", herohp)
func _on_Button3_pressed():
print ("herohp: ", herohp)