• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Where to save savedgames on Android?

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,414
Where are you supposed to save savedgames on Android to make sure it will survive an storeupdate?
 
What do you mean by storeupdate? Did you try just using SaveState()? What are the issues you ran into?
 
I have to admit that the saving-file thing is a total confusion for me right now. I havn't tried SavedState that's a brand new instruction to me. I'm currently saving all files using databuffer into the datafolder. I think. Does it need to be saved outside the datafolder or what are you supposed to do? It's just game data under 10MB so it's not anything massive.
 
Well, IFAIK this is the multiplatform way of CX for all generated data that need to be saved. I used it to track user input and let the game react accordingly. It has been some time, but I think on android these data are kept even if you update your game, given that you don't change the identifying stuff.
On Windows I had some issues with an installer (InnoSetup) to make it writeable and keep the data, if you install an update over it, but it worked fine the last time I tried.

Generally I was using JSON to structure the data and have it readable while decently packed.
 
@jimmyon imho on Android AND ios, you can't write into the data folder. You can only read from there.
 
When i find time, i will outline where android saves the content when you target the internal folder. Have to dig into the sources for this.
Btw, didn't you had this figured out by writing to the SD card?
 
Yes exactly saving to external card is no problem. You just have to manually go to Settings/Apps/CerberusGame and allow fileaccess. I think I can write JAVA runtime asking routine to handle that correctly.

The external I can decide exactly where to save, here I save it in my camera folder and load it back.

Also it works using "internal" but I can't find it right now where that goes right now.


Cerberus:
Strict
Import mojo2
Import brl
Import brl.FileSystem

Function Main:Int()
    New myClass
    Return 0
End

Class myClass Extends App

    Field so:String[], canvas:Canvas, bg:Image
   
    Method OnCreate:Int()
        SetUpdateRate 0
        canvas = New Canvas
       
        ' Write file
        Local s:String
        s = "brian~nJohn~nPeter"
         Local fw:= FileStream.Open("cerberus://internal/test2.txt","w")
        'Local fw:= FileStream.Open("cerberus://external/DCIM/Camera/test4.txt","w")
        If fw <> Null
            Print "File open to write"
            fw.WriteString(s)
            fw.Close()
        Else
            Print "File not open to write"
        Endif
       
        ' Read file
        Local fr := FileStream.Open("cerberus://internal/test2.txt","r")
        'Local fr := FileStream.Open("cerberus://external/DCIM/Camera/test4.txt","r")
        If fr <> Null
            Print "File open to read"
            Local s2:String = fr.ReadString()
            fr.Close()
            Print ("------------------")
            Print ("s2="+s2)
            Print ("------------------")
            so = s2.Split("~n")
            Print ("Count="+so.Length())
        Else
            Print "File not open to read"
        Endif
       
        Return 0
    End

    Method OnUpdate:Int()
        Return 0
    End

    Method OnRender:Int()
        canvas.Clear 0,0,0.5
        canvas.SetColor 0.5,0.5,0.5
        canvas.PushMatrix
        canvas.Translate DeviceWidth()/2,DeviceHeight()/2
        canvas.Scale 2.0,2.0
        canvas.DrawText( String("Cerberus X~nHello World!").Split("~n")),DeviceWidth()/2,DeviceHeight()/2,0.5,0.5
        For Local y:Int = 1 To so.Length()
            canvas.DrawText so[y-1], 0, 0+y*20, .5, .5
        Next
        canvas.PopMatrix
        canvas.Flush
        Return 0
    End
   
End
 
Here I successfully could make a DIR to list all internal created files (it seem to repeat though)

Cerberus:
Strict
Import mojo2
Import brl
Import brl.FileSystem

Function Main:Int()
    New myClass
    Return 0
End

Class myClass Extends App

    Field so:String[], canvas:Canvas, bg:Image
    
    Method OnCreate:Int()
        SetUpdateRate 0
        canvas = New Canvas
        
        ' Write file
        Local s:String
        s = "brian~nJohn~nPeter"
        Local fw:= FileStream.Open("cerberus://internal/test2.txt","w") 
        'Local fw:= FileStream.Open("cerberus://external/DCIM/Camera/test4.txt","w")
      
   If fw <> Null
            Print "File open to write"
            fw.WriteString(s)
            fw.Close()
        Else
            Print "File not open to write" 
        Endif
        
        ' Read file
        Local fr := FileStream.Open("cerberus://internal/test2.txt","r")
        'Local fr := FileStream.Open("cerberus://external/DCIM/Camera/test4.txt","r")
      
   If fr <> Null
            Print "File open to read"
            Local s2:String = fr.ReadString()
            fr.Close()
            Print ("------------------")
            Print ("s2="+s2)
            Print ("------------------")
            so = s2.Split("~n")
            Print ("Count="+so.Length())
        Else
            Print "File not open to read" 
        Endif
        
        Return 0
    End

    Method OnUpdate:Int()
    
    
       If MouseDown(0)
        Local y:=0
        For Local f:=Eachin LoadDir( "cerberus://internal/",True )
            Local p:=""+f
            Local nm:=(f+"                    ")[..20]
            Local ty:=""
            If FileType( p )=FILETYPE_FILE
                ty=FileSize( p )
            Else
                ty="(dir)"
            Endif
        Print nm+ty
        Next
        
        Endif
        
        Return 0
    End

    Method OnRender:Int()
        canvas.Clear 0,0,0.5
        canvas.SetColor 0.5,0.5,0.5
        canvas.PushMatrix
        canvas.Translate DeviceWidth()/2,DeviceHeight()/2
        canvas.Scale 2.0,2.0
        canvas.DrawText( String("Cerberus X~nHello World!").Split("~n")),DeviceWidth()/2,DeviceHeight()/2,0.5,0.5
        For Local y:Int = 1 To so.Length()
            canvas.DrawText so[y-1], 0, 0+y*20, .5, .5
        Next
        canvas.PopMatrix
        canvas.Flush
        Return 0
    End
    
End
 
Some progress :

* I got Load/Save-state working and it seems to work on all platforms desktop including android even html. But I'm not sure what I can save and load its more a snapshot of some global state and not files? It seems a bit weird but handy to have.

* Load/Save external (works and I know where it is but I don't think it's good practice to use in such situations).

* Load/Save Internal works equally I can read and write data and all is well, but I havn't found where the actual data hides.
I've tried to find an app folder inside my phones' Android/data folder but it's not there.

About the data folder I still can't find the .data folder on android but on desktop I think I can cd to that dir but I havn't had the time to test if its okay to do it even on desktop. Will try this after Christmas.
 
I can for sure read from the .data folder and write to local and keep reading from local instead IF it exist there (even if i'm a bit bothered about not being able to see the folder) but I'm sure there's a reason for this as I seen al lot of people have the same "problem" with their games developed with Android Studio.
 
Back
Top Bottom