I'm trying to set up a program where it loads the player's position at the start of the level but when I try to get the data from the dictionary I saved it in I get this error.
invalid get index 'player_x' (on base: 'dictionary')
I've been loosely following this tutorial (https://www.youtube.com/watch?v=mV86a8TWSc4) and my code seems to match up however I have made significant changes to suit my program.
how do I fix this?
relevant code:
code for scene:
extends Node2D
onready var player = $player
onready var game_data = SaveFiles.game_data
func _ready():
SaveFiles.load_data()
SaveFiles.save_data()
if SaveFiles.enter == true:
player.position.x = game_data.player_x
SaveFiles.enter = false
else:
player.position = Vector2 (970,300)
code in autoload:
func load_data():
var file = File.new()
if not file.file_exists(current):
game_data = {
"player_name": "farmer",
"player_x": 100,
"player_y": 100,
}
save_data()
file.open(current, File.READ)
game_data = file.get_var()
file.close()