• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Android Ini File not working?

A

AsePlayer

Guest
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?
 
A

AsePlayer

Guest
This is not expected to not work. Therefore, please post all relevant code.
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.
 

TsukaYuriko

☄️
Forum Staff
Moderator
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.
 
A

AsePlayer

Guest
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.
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?
 

TsukaYuriko

☄️
Forum Staff
Moderator
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.
 
A

AsePlayer

Guest
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.
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?
 
D

Death

Guest
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 by a moderator:

TsukaYuriko

☄️
Forum Staff
Moderator
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?
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
 
A

AsePlayer

Guest
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
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
 
Top