GameMaker Cant write to .ini file

X

Xarddrax

Guest
I am having a horrible time for the last 2 hours trying to figure out why i cant update my .ini file with a script.
I am able to test the file exists. I am able to read the keys (at least see they exist) but I cant change them. I am running this script from an alarm every 600 ticks. Everytime I check the file using the resource explorer ("Included Files" tree) there is the same default setting I manually entered.

Here is the script being called:

Code:
//update .ini file and current states

hp=obj_status.playerHp;
hpMax=obj_status.playerHpMax;
mp=obj_status.playerMp;
mpMax= obj_status.playerMpMax;
xp= obj_status.playerXp;
xpMax= obj_status.playerXpMax;
pbattles= obj_status.playerBattles;
hitC= obj_status.pHitChance;
critC=obj_status.pCritChance;
deaths=obj_status.pDeaths;
dmg=obj_status.playerDmg;



/* //----Test to see if the file is there---
if (file_exists(working_directory + "\player.ini"))
{show_message("its here");}
*/


ini_open(working_directory + "\player.ini");

if ini_key_exists("playerStats", "hp")
{show_message("key is here");}


ini_write_real("playerStats", "hp", hp);
ini_write_real("playerStats", "hpMax", hpMax);
ini_write_real("playerStats", "mp", mp);
ini_write_real("playerStats", "mpMax", mpMax);
ini_write_real("playerStats", "xp", xp);
ini_write_real("playerStats", "xpMax", xpMax);
ini_write_real("playerStats", "pbattles", pbattles);
ini_write_real("playerStats", "hitC", hitC);
ini_write_real("playerStats", "critC",critC);
ini_write_real("playerStats", "deaths", deaths);
ini_write_real("playerStats", "dmg", dmg);


ini_close();
 
When you read from the ini file, it reads the values from the Included File (unless you have previously written to it, then it will use the copy of the file that you wrote, and it's location will be determined by what platform you are running on)

When you write to the ini file, it creates a copy of the file in the working directory. This is where you will find the changes you have made.

This is why you won't see any changes in the Included File

Check the File Systems section in the manual for details.
 
X

Xarddrax

Guest
So the "Included File" is only used as a placeholder and never written to (unless you do it beforehand)?
 

sylvain_l

Member
So the "Included File" is only used as a placeholder and never written to (unless you do it beforehand)?
yep.
GMS is sandboxed, that means in general you can't write outside the %appdata%/gamename location. (desktop win module)
so in case of ini file and other file you want to write to; the included version is just the fallback version to read to while you haven't yet created it in the %appdata%/gamename folder
 
Top