Load/save persistent data on mobile targets?

About Monkey 2 Forums Monkey 2 Programming Help Load/save persistent data on mobile targets?

This topic contains 14 replies, has 7 voices, and was last updated by  abakobo 1 year, 6 months ago.

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #10822

    mat
    Participant

    Hi all,

    Is there an equivalent to the old LoadState() and SaveState() for mobile targets? These should load and save strings that are persistent between installations of the app, used to e.g. store high scores and preferences between reinstalls. I can’t see anything in the docs but probably missed it…

    Thanks!

    #10824

    nerobot
    Participant

    Try to use that:

    #10826

    AdamStrange
    Participant

    where are you getting InternalDir() from?

    #10827

    nerobot
    Participant

    where are you getting InternalDir() from?

    std.filesystem namespace.

    #10832

    AdamStrange
    Participant

    ok. how would this work for desktop?

    #10834

    TomToad
    Participant

    On windows, you can use GetEnv(“appdata”) to get the aplication data directory, then append “/myprogramname/data/” to it.
    Local Dir:=GetEnv(“appdata”)+”/myprogramname/data/”
    CreateDir(Dir)
    etc…

    Don’t know if that would work on other platforms. Monkey probably should have a command like AppDataDir() to return the place to store persistent data across all platforms.

    #10835

    nerobot
    Participant

    ok. how would this work for desktop?

    Topic about mobile. 😉

    For desktop there are AppDir () AssetsDir () HomeDir ().

    #10837

    Ethernaut
    Participant

    Maybe I’m oversimplifying here, but isn’t it enough to create a text file in a folder where the main monkey file is, then just:

    From then on, simply use SaveString and LoadString with the file asset, like this:

    myFile.txt is copied to the build folder when you build the app, and “lives” with the app from now on, allowing persistent data to be saved and loaded. The original file is unaltered when the app saves the string, since it now saves over the copy in the build folder instead of the original.

    (never tried it on mobile, but should work, shouldn’t it?)

    #10840

    mat
    Participant

    Thanks for all the replies!

    According to the Android developer docs the internal storage is lost when the user uninstalls the app. It isn’t clear if it is kept on re-install (e.g. upgrading) the app, but this isn’t quite the persistency that i’m looking for.

    For my particular use case, I’m going to be unlocking levels as the user progresses through the game, and i’d like that information to remain if the user uninstalls (how dare they!) and re-installs later, or if there is an upgrade (e.g. bug fixes). I think this should be standard behaviour on mobile platforms to store this kind of data persistently?!

    Edit: It looks like the old Monkey uses SharedPreferences on Android and something else that I don’t understand on iOS to achieve this. I don’t suppose anyone has implemented this in the new Monkey?

    #10841

    nerobot
    Participant

    If you will store data in external storage – user can formatting sd-card and lose your data.

    Need to use cloud-based storage like google-drive or play-services.

    #10842

    mat
    Participant

    Hi nerobot,

    I just added an edit to my above post on how the old Monkey implements persistency through re-installs. I think if the user completely reinstalls their device then i’m not going to be overly bothered if they lose their game progress (maybe I should be?!) but just for upgrading the app, this data should be stored.

    #10843

    nerobot
    Participant

    I think when user uninstall app he expects data losing.

    AFAIK private shared prefs also will be removed on app uninstall.

    #10844

    mat
    Participant

    Yeah you’re probably right on shared prefs being removed also. I slightly disagree on the user expecting to lose the data though, but maybe a cloud based method is best for storing this as you suggest.

    Thanks for the help!

    #10863

    Mark Sibly
    Keymaster

    IMO, a web/cloud solution is best here, as a user *should* be able to wipe device data the way they can wipe apps if they want, so if you want data to be truly recoverable, it should probably be stored off device, perhaps even on an SD card?

    Are there any android/ios APIs for accessing google drive or icloud?

    #10865

    abakobo
    Participant

    For games, on andrid there’s “google play games”, on ios it’s on the “game center” I think, but I only have an android for now..
    (dunno for files cloud)

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.