Android Ini File not working?

Discussion in 'Programming' started by AsePlayer, Feb 6, 2019.

Tags:
  1. AsePlayer

    AsePlayer Member

    Joined:
    May 1, 2018
    Posts:
    7
    I use ini files to keep track of my app's total gold, etc. It works on the test and when I try and run it on an android device it seems to just straight up not work. Is there a fix or an alternative?
     
  2. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,536
    This is not expected to not work. Therefore, please post all relevant code.
     
  3. AsePlayer

    AsePlayer Member

    Joined:
    May 1, 2018
    Posts:
    7
    I have this on every room creation code.
    ini_open("savedata.ini");
    global.gold = ini_read_real("savegame", "score", 0);
    ini_close();

    When the level concludes, (via an alarm going off) I have
    ini_open("savedata.ini");
    ini_write_real("savegame", "score", global.gold+gamegold);
    ini_close();

    I also have a text to display global.gold after it loads in the draw event, and while it works on PC, it just displays 0 on android.
     
  4. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,536
    Is this code actually running? Verify it using something that will make itself noticeable if the code runs.

    Is the file actually being created (and, by extension, accessible)? Verify it using file_exists or reading the file's contents after it has been created.
     
  5. AsePlayer

    AsePlayer Member

    Joined:
    May 1, 2018
    Posts:
    7
    The code appears to not be running at all. I used
    if file_exists("savedata.ini")
    obj_base.player_hp = 10000

    Works for pc, not for android. So is the file just straight up not being created or do ini's just not work on mobile? I'm relatively new to mobile development and I just used some simple ini code so I don't know.

    If ini's don't work on mobile, is there an alternative that will work?
     
  6. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,536
    They are expected to work on mobile.

    Be careful when pointing fingers at code that may or may not have ran, though - what you did was add entirely separate code. Perform the check right next to the code that's supposed to be running to verify that it runs. From a problem-solving standpoint, there is a huge difference between the save code not running at all and the save code running but failing to producing a file.

    Just to make sure we're on the same page here: How are you running the game on your Android device? The expected procedure is to build an APK file, install it on the device and run it.
     
  7. AsePlayer

    AsePlayer Member

    Joined:
    May 1, 2018
    Posts:
    7
    I haven't really "built" an apk per say, I've been using the target build on an emulator from Android Studio. Does the apk need to be fully done and installed to actually make the .ini's work?
     
  8. Death

    Death Member

    Joined:
    Aug 8, 2018
    Posts:
    81
    Connect your phone to your computer then generate the apk and it should start running on your phone.
    If this step works, then what you write to the .ini is NOT what you think it is. Check the file on your computer and see if it actually contains your data the way it should be. If that is OK than it must be your emulator causing it.
    I am willing to bet thought that the data you write is NOT the data you expect to read, if it isn't your emulator. Start checking that first...
     
    Last edited: Feb 7, 2019
  9. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,536
    Try building an APK and running it directly on a target device, removing the potential additional problem sources that are the emulator and the test build runner. The answer this process will produce should be more conclusive than any of my educated guesses about what could be interfering with the permissions in between, so let's leave it at an inconclusive "I can see a few things that could go wrong there" to further motivate you to test it out. :D
     
  10. AsePlayer

    AsePlayer Member

    Joined:
    May 1, 2018
    Posts:
    7
    I'll work on it and keep you updated! Sorry for not being super helpful in this, new to game maker and game making in general! :p
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice