Resources > Coding
Small INI issue.
(1/1)
Whitay:
Hello all. I am designing a small little game to take a break from FOH and get a bit better at coding in general, and i have gotten to a point where i need to start saving a little bit of data(just max health, money, upgrades, etc. its like a temple run type game.) and i have never worked with these for saving. i understand how to write them and how to read them with code, but i have one issue. creating it and putting starting data in it. is there an easy way to say like
if the INI doesnt exist/is blank/whatever or if this global.maxhp is undefined then global.maxhp = 1 or whatever?
or is there a better way to get save data of just a few variables into the game? I am thinking of porting this game to HTML or something, maybe IPhone if i spend enough time on it. is there a way of saving that would work no matter the system? or atleast works with regular gm and then the in web browser version?
Jeod:
You would either ship the ini file with your executable and encrypt it, or you would need to write the ini file from GM as if it were a text document, save it with the .ini extension, and then read from it.
MG-Zero:
Encrypting it would be silly. I see the purpose, but it's not like a game is a high security environment. Plus it will slow down loading.
Otherwise, it's simple enough like Jeod said to just write it as a text file from GM or whatever language you're using.
Theforeshadower:
What I usually do:
--- Code: ---if file_exists("gameData.ini")
{
//do all my loading here - I will call my global loading of the ini here as well usually on the title/start screen
global.saveFile = ini_open("gameData.ini");
//finish loading each variable or you could just have the game load from the ini on the fly instead of loading into global variables
}
else
{
//Game Maker 8.1 and older
temp = file_open_write("gameData.ini");
file_close(temp);
global.saveFile = ini_open("gameData.ini");
//Game Maker Studio
ini_open("gameData.ini");
//note that GMS only creates the ini if you write data to it so you should have your keys created after you open the ini
}
--- End code ---
That code isn't perfect as I haven't used it in a while and I no longer have GM 8 installed to check it. GM Studio changed the file system and it seems a bit wonky. You should look into the manual if you are using GMS as it already includes many levels of encryption standard now from base64 upto SHA-1.
Whitay:
Thank you both, i will try those suggestions. I am in Game Maker 8 but wish to transfer over to GMS, so i may as well do that sooner or later. thank you both for the replies!
Navigation
[0] Message Index
Go to full version