now saving persistent data
includes number of enemies killed, number of times died, last killed
This commit is contained in:
63
scripts/save_load.gd
Normal file
63
scripts/save_load.gd
Normal file
@@ -0,0 +1,63 @@
|
||||
extends Node
|
||||
|
||||
## SAVE DATA
|
||||
#Persistent
|
||||
var last_hit_path
|
||||
var player_deaths
|
||||
var enemies_killed
|
||||
|
||||
## SAVE DATA PATHS
|
||||
var persistent_save_path = "user://persistent_data.save"
|
||||
|
||||
func _ready() -> void:
|
||||
if player_deaths == null:
|
||||
player_deaths = 0
|
||||
if enemies_killed == null:
|
||||
enemies_killed = 0
|
||||
|
||||
func save_persistent_data():
|
||||
var file = FileAccess.open(persistent_save_path, FileAccess.WRITE)
|
||||
print("LAST HIT PATH " + str(last_hit_path))
|
||||
file.store_var(last_hit_path)
|
||||
file.store_var(player_deaths)
|
||||
print("SAVING PLAYER DEATHS " + str(player_deaths))
|
||||
file.store_var(enemies_killed)
|
||||
print("SAVING ENEMIES KILLED " + str(enemies_killed))
|
||||
|
||||
func load_persistent_data():
|
||||
if FileAccess.file_exists(persistent_save_path):
|
||||
var file = FileAccess.open(persistent_save_path, FileAccess.READ)
|
||||
last_hit_path = file.get_var()
|
||||
print("CROWN PARENT : " + str(last_hit_path))
|
||||
player_deaths = file.get_var()
|
||||
print("PLAYER DEATHS : " + str(player_deaths))
|
||||
enemies_killed = file.get_var()
|
||||
print("ENEMIES KILLED : " + str(enemies_killed))
|
||||
else:
|
||||
print("no data saved...")
|
||||
last_hit_path = null
|
||||
player_deaths = null
|
||||
enemies_killed = null
|
||||
|
||||
func save_game_data():
|
||||
pass
|
||||
|
||||
func load_save_game_data():
|
||||
pass
|
||||
|
||||
func data_validate(file,variable):
|
||||
if file.get_var(variable):
|
||||
return file.get_var(variable)
|
||||
else:
|
||||
return null
|
||||
|
||||
func persistent_data_calc(variable,amount):
|
||||
if variable == null:
|
||||
variable = amount
|
||||
print(str(variable) +" "+ str(amount))
|
||||
else:
|
||||
variable += amount
|
||||
|
||||
func load_data():
|
||||
load_persistent_data()
|
||||
load_save_game_data()
|
||||
Reference in New Issue
Block a user