Looking at the picture above, it appears that current_line
is equal to null
, which appears to be why it is failing.
I do not know if it it will work or not, but I rewrote the code visible in the picture above to, hopefully, include all the conditionals needed to work around newlines and empty strings. I formatted the code a bit so it would fit better in this post.
I would copy/backup the script file before trying the code below, as I have no idea if it will work or not.
# starting at line 34
while not save_game.eof_reached():
var current_line = save_game.get_line()
if current_line == null:
continue
elif current_line.empty():
continue
else:
var json_dictionary = parse_json(current_line)
if json_dictionary == null:
continue
else:
if json_dictionary.has("filename"):
var new_object = load(json_dictionary["filename"]).instance()
add_child(new_object)
new_object.position = Vector2(json_dictionary["pos_x"],
json_dictionary["pos_y"])
for i in json_dictionary.keys():
if i == "filename" or i == "parent" or i == "pos_x" or
i == "pos_y":
continue
new_object.set(i, json_dictionary[i])
save_game.close()
It might be a tad overdone, but the code above should hopefully work.