Godot Version
4.2.2 stable
Question
I am trying to make code to create a world and save the data, but it doesn’t create anything and prints out an error (that I placed). Can anybody help me?
Heres the code:
func save_world():
var saved_worlds = list_saved_worlds()
if saved_worlds.size() >= 10:
print("Maximum number of saved worlds reached. Cannot save more.")
return
var use_space = true
var timedict = Time.get_datetime_dict_from_system(use_space)
var time = Time.get_datetime_string_from_datetime_dict(timedict,use_space)
var file_path = "user://Saves/world_" + time + ".MW"
print("Saving world to file:", file_path)
var file = FileAccess.open(file_path, FileAccess.WRITE)
if !file:
print("Error opening file for saving")
return
for block in get_children():
if block is StaticBody3D:
file.store_var(block.transform.origin)
print("Saved block at position:", block.transform.origin)
file.close()
print("World saved successfully at ", file_path)