Makeing saves in game

godot 4

i am having some trouble with saving my game and was looking for help
here is the code
thanks

var json = JSON.new()
var path = “user://data/RPGGAME.json”
var data = {}
var content = {gold:gold, health:health, playerSpeed:playerSpeed, bootsON:bootsON, highestFloor:highestFloor, startFloor:startFloor, daveInMainLevel:daveInMainLevel, giveDaveGold:giveDaveGold, daveShopOpen:daveShopOpen, fairyBottle:fairyBottle}

func save(content):
var file = FileAccess.open(path, FileAccess.WRITE)
file.store_string(JSON.stringify(content))
file.close()
file = null

func create_new_save():
var file = FileAccess.open(“res://Deftult_data.json”, FileAccess.READ)
content = JSON.parse_string(file.get_as_text())
data = content
save(content)

func load_game():
if FileAccess.file_exists(path):
var file = FileAccess.open(path, FileAccess.READ)
content = JSON.parse_string(file.get_as_text())
return content
else:
create_new_save()

What problem do you suffering? Saving or loading

when saving i get the error
Attempt to call function ‘store_string’ in base ‘null instance’ on a null instance.

check FileAccess.get_open_error() when FileAccess.open returned null

Ok, show the full codes and delete the data file from your computer (C:\Users\User\AppData\Roaming\Godot\app_userdata\your_project\data.dat)

i have managed to get the saving working now but now this issue is when loading i don’t know how to get the save from content which is the data as text so i need to get the content and change it back into the var’s

never mind i have fixed it thanks for the help

1 Like