Makeing saves in game

godot 4

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

var json =
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.WRITE)
file = null

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

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

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 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