Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Cobra! | |
Old Version | Published before Godot 3 was released. |
I’m following this tutorial for learning how to load and save games, but I’m come across a problem when I try to test it.
I get the error:
invalid get index 'save_path' (on base: 'null instance').
even though “save_path” is defined.
Here’s my code:
extends Node
export(StringArray) var save_data_names
export(Array) var saveData
var save_data = {}
var savegame = File.new()
export var save_path = "user://user.bin"
onready var global_node = get_node("/root/global")
func _ready():
# Called every time the node is added to the scene.
# Initialization here
if save_data_names:
for i in range(save_data_names.size()):
save_data[save_data_names[i]] = saveData[i]
check_savegame()
func check_savegame():
print(savegame.file_exists(save_path))
if !savegame.file_exists(save_path):
savegame.open_encrypted_with_pass(save_path, File.WRITE, OS.get_unique_ID())
savegame.store_var(save_data)
savegame.close()
else:
savegame.open_encrypted_with_pass(global_node.save_path, File.READ, OS.get_unique_ID())
save_data = savegame.get_var()
savegame.close()
func saveData():
savegame.open_encrypted_with_pass(save_path, File.WRITE, OS.get_unique_ID())
savegame.store_var(save_data)
savegame.close()
func setKey(key, value):
save_data[key] = value
func getValue(key):
if saveData.has(key):
return saveData[key]
else:
return null
What do I do?
Are you trying to access save_path
from somewhere else?
I think it says you are trying to get save_path
from a null reference.
eons | 2017-05-17 16:54
savegame.open_encrypted_with_pass(global_node.save_path, File.READ, OS.get_unique_ID())
are you sure global_node
has save_path
variable?
volzhs | 2017-05-17 17:33