Save Problem in Android

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Xenapibe
extends Label

var level = 1
var savesystemnumber = 0
var savepath

func save():
var SaveFile = File.new()
var data: Dictionary ={“lvl”:level,
“number”:savesystemnumber}
SaveFile.open(“user://lvlss.dat”, File.WRITE)
SaveFile.store_var(data)
SaveFile.close()

func loadsystem():
var SaveFile = File.new()
if !SaveFile.file_exists(“user://lvlss.dat”):
return
SaveFile.open(“user://lvlss.dat”,File.READ)
var data = SaveFile.get_var()
level = data[“lvl”]
savesystemnumber = data[“number”]
SaveFile.close()

You haven’t described what the actual problem is…

jgodfrey | 2022-11-10 15:23

Save works in Windows, but doesn’t work in Android.

Xenapibe | 2022-11-11 05:33

When I close and reopen the game on Windows, I can continue where I left off, but on Android this does not work.

Xenapibe | 2022-11-11 05:33

I don’t see anything inherently wrong with the posted code, though since it’s not formatted as code for the forum, some details are being lost…

That said, a few questions / comments:

  • Is the save file being created but not loaded on Android, or is it not being created? I assume it’s not being created.
  • If see the load call just silently returns if the save file doesn’t exist.
  • I’d guess this is likely a permissions issue on your Android device. You could / should add some more error checking to the code to help spot the problem.
  • You can always set up a remote debugging session on the device to better spot the problem…
  • I’d recommend that you put your filename in a single variable and reference it in all the places where you have a hardcoded name now. That’ll prevent any unintended differences in the name(s)…

jgodfrey | 2022-11-11 14:50