Godot Version
4.22
Question
To anyone reading, I’m quite new to the save/loading world and have been scratching my head over this one for over a week.
I’ve got three save slots which, when saving or when openning the save/loading screen, shows images acording to the saved level.
Globals.level is the only variable being saved so I think this is about as simple as it gets.
When the save/load screen opens, it triggers the “get_save_slots()” to load the corresponding level images. Then a the end of the save or load function, which ever is triggered, it sets off the timer which plays an animation before the scene changes.
On my computer it works fine, but for others it does nothing. Any thoughts? I’m know I’m not quick, but…
Code is as follows
################
var documents_path : String = “user://”
func get_save_slots():
var save_slots = [ ]
for i in range(1,4):
var save_path = documents_path + "slot_" + str(i) + ".save"
if FileAccess.file_exists(save_path):
save_slots.append(i)
var save_contents = FileAccess.open(save_path,FileAccess.READ)
var print_level = save_contents.get_var()
if i == 1:
slot_picture_1.texture = slot_images["level" + str(print_level)]
elif i == 2:
slot_picture_2.texture = slot_images["level" + str(print_level)]
elif i == 3:
slot_picture_3.texture = slot_images["level" + str(print_level)]
func save_game(slot:int):
input_disabled = true
if not DirAccess.dir_exists_absolute(documents_path):
DirAccess.make_dir_absolute(documents_path)
var save_path = documents_path + "slot_" + str(slot) + ".save"
var save_data = Globals.level
var save_file = FileAccess.open(save_path,FileAccess.WRITE)
if slot == 1:
slot_picture_1.texture = slot_images["level" + str(Globals.level)]
elif slot == 2:
slot_picture_2.texture = slot_images["level" + str(Globals.level)]
elif slot == 3:
slot_picture_3.texture = slot_images["level" + str(Globals.level)]
save_file.store_var(save_data)
save_file.close()
loading_or_saving_is_happening = false
timer.start()
func load_game(slot:int):
input_disabled = true
var save_path = documents_path + "slot_" + str(slot) + ".save"
if not FileAccess.file_exists(save_path):
input_disabled = false
print("Does not exist")
return
var save_file = FileAccess.open(save_path,FileAccess.READ)
var saved_data = save_file.get_var(true)
Globals.level = saved_data
save_file.close()
timer.start()