Save & Load Strings (Game)

hasexxl1988

Active Member
Licensed User
Longtime User
Hello, I wanted to ask how can I set this up, that certain values ​​are saved and start again the next app to be loaded. e.g. lvl degrees in a game.
e.g.
lvl1 = 1
lvl2 = 1
lvl3 = 1
lvl 4 = 1
lvl5 = 0
lvl6 = 0
etc.

Thanks in advance
 

kickaha

Well-Known Member
Licensed User
Longtime User
I tend to define a Type called prefs that has all the variables I want to save - something along these lines:
B4X:
   Type prefs (lvl1, lvl2, lvl3, lvl 4, lvl5, lvl6 As Int)

I can the load and save using:
B4X:
Sub LoadPrefs
   Dim raf As RandomAccessFile
   raf.Initialize(File.DirInternal , "prefs.sav", True)
   prefs = raf.ReadObject (raf.CurrentPosition)
   raf.Close
End Sub
Sub SavePrefs
   Dim raf As RandomAccessFile
   raf.Initialize(File.DirInternal , "prefs.sav", False)
   raf.WriteObject(prefs, True, raf.CurrentPosition)
   raf.Close
End Sub

Obviously with a bit more error checking etc.
 
Last edited:
Upvote 0
Top