Godot Version
Godot 4.5 stable
Question
I’m trying to add a save/load system for the level editor in my game. I implemented a simple test save and load, and it seems to work fine from my testing, but I still get this error whenever I load the project:
ERROR: scene/resources/resource_format_text.cpp:40 - res://addons/gaia_sys/map.tres:1 - Parse Error: .
ERROR: scene/resources/resource_format_text.cpp:878 - Condition "error != OK" is true.
Here’s my save/load script.
@tool
extends TileMapLayer
const Map_Path = "res://addons/gaia_sys/map.tres"
var map_file : FileAccess
var rooms : Array = ["potato"] # random debug value
func _ready() -> void:
if FileAccess.file_exists(Map_Path): # detects if the file already exists.
map_file = FileAccess.open(Map_Path, FileAccess.READ) # opens the file to read.
rooms = map_file.get_var() # loads the array from the file into a variable.
print(rooms) # print for debugging
map_file.close() # close the file
tile_map_data.clear() # clear the tilemap (unrelated to the issue)
func add_room(position:Vector2i): # add room to the map (also unrelated)
set_cell(position, 0, Vector2i(1, 0))
func save_map():
print("save!") # debug save message
map_file = FileAccess.open(Map_Path, FileAccess.WRITE_READ) # opens and trunkates file
map_file.store_var(rooms) # save variable to file
map_file.close() # close file
print(FileAccess.file_exists(Map_Path)) # debug message to confirm file