Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Juwu |
I’m trying to save many variables on a dictionary, but something’s wrong, I add 3 variables on the dictionary but only the second variable does not work, when I try to load this variable on another this error appears
Invalid get index 'the variable' (on base dictionary)
This happens whit me on other projects but I just change the name of the variable on the dictionary and work, but now I don’t know what’s the problem
The Code:
func save():
var data := {
"dictuoinaruyadfs": Game.Monkes2,
'Score': Game.score,
'Monkes_inst': Game.Monkes
}
var save_file = File.new()
var error = save_file.open('res://Save/save.tres' , File.WRITE)
if error == OK:
save_file.store_var(data)
save_file.close()
else:
print('ocorreu um erro ao salvar o arquivoo')
save_file.close()
func lod():
var save_file = File.new()
var erro = save_file.open('res://Save/save.tres' , File.READ)
if not erro:
var saved_data = save_file.get_var()
Game.score = saved_data['Score']
Game.Monkes = saved_data['Monkes_inst']
Game.Monkes2 = saved_data["dictuoinaruyadfs"]
for position in Game.Monkes:
var new_monkes = preload('res://Scenes/MONKE.tscn')
var monke_spawn = new_monkes.instance()
monke_spawn.position = position
get_parent().add_child(monke_spawn)
for position in Game.Monkes2:
var new_monkes2 = preload('res://Scenes/Monke2.tscn')
var monke_spawn2 = new_monkes2.instance()
monke_spawn2.position = position
get_parent().add_child(monke_spawn2)
for position in Game.Monkes3:
var new_monkes3 = preload('res://Scenes/Monke2.tscn')
var monke_spawn3 = new_monkes3.instance()
monke_spawn3.position = position
get_parent().add_child(monke_spawn3)
else:
print('erro ao carregar')
save_file.close()
The Variables:
var Monkes = []
var Monkes2 = []
var Monkes3= []
Ps: these variables are on the autoload, so it’s in another code