• 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!

GameMaker (SOLVED) Save File INI Help - Saving + Loading Variables Issue

Vinsane

Member
Hi there everyone,

I currently have a working INI save system (that is very basic mind you) that saves what fields I enter into it.
at the moment I have saved the players "kills" and "coins" so when I relaunch the game and hit load these two variables will load up fine with the objects assigned to them.

At the moment the game will auto-save at the start of every level. My issue is that I'm trying to save the variables of the clothes system that I've created.

I have a main clothes controller that has global variables assigned to 4 different button presses. up on arrow key will increase the global var assigned to that piece of clothing, example below.

global.tops = 1 will spawn a t-shirt on the player,
global.tops = 2 will remove the previous t-shirt and replace it with a new one, and so on and so on.

My goal is to have 4 new variables in my INI file -
Hats="0"
Shoulder Pads="0"
Pants="0"
Tops="0"

I have achieved the writing to the INI file fine but I am unable to get the code to actually save the global variable assigned to each of the string. the weird thing is that my global kill counter and gold counter works fine but I just cannot get the clothes variables to work at all. it always saves 0 instead of the real global variable

Here is the code I am using for saving the var's
ini_write_real("Clothes","Hats",global.hats);
and for the load
global.hats = ini_read_real("Clothes","Hats",0);

Can anyone please lend me some assistance because I don't understand what I'm doing wrong.

The only thing I can imagine is that it is because I have not written in to save the clothes controller in the save script. that is because my knowledge is very limited when it comes to saving objects instead of variables.
 
N

northlight

Guest
Depending on how you are doing it it's very important you save and load before these things are stated so like if you load your game and you have something that says

global.hats = 0 on a create event then it doesnt matter if you load it, the game will always switch whatever you load and change it to 0

So what this looks like is as follows
1. at the menu
2. push load
3. global.hats = 4
4. game starts
5 theres a create event it says global.hats = 0
6 so now when you start the game no matter what your hats are 0

I stress this with a lot of people, you must save all vars that are part of how your game runs not just some because thats when you run into errors. On one of my games I saved literally everything from buildings x y to the character and all of his stats and enemies I saved it all so it matched EXACTLY with where I left off because if the game was working BEFORE you saved and its identical then you cant have errors when you load an exact copy.
 

Vinsane

Member
UPDATE: It seems I have managed to get the objects to appear when I insert the clothes code into the load script, only issue is now it is loading up random clothes instead of the set numbers. It seems every time I hit the load button it completely generates new combination of clothing instead of the set variables that are listed in the save. Would anyone have any idea why this could be happening? UPDATE AGAIN: I might have solved it. tweaked the code and removed any delete clothes on arrow keypress from load script. things are looking like they are working OK. will give final update tomorrow.

Thank you very much I now have the correct clothes numbers being written to the ini file!

The only issue is now the objects do not spawn in that the numbers were assigned to if that makes sense.

now when I save my game I have
global.hats = 4

but when I load the game the corresponding object does not appear on the player. when I press the arrow key it actually spawns the next item in the list with no problems but it seems loading the actual objects that I saved will be the next big issue.

Can you please assist?
I really appreciate the help by the way!

Here is the clothes section in my load script:

global.pants = ini_read_real("Clothes","Hats",0);
global.hats = ini_read_real("Clothes","Tops",0);
global.tops = ini_read_real("Clothes","Pants",0);
global.shoulderpads = ini_read_real("Clothes","Shoulder Pads",0);

here is the actual ini file =

[Clothes]
Shoulder Pads="0.000000"
Pants="1.000000"
Tops="5.000000"
Hats="1.000000"

How do I go about getting the clothes to spawn with the corresponding numbers? I feel like I'm so close yet so far to cracking this puzzle.

Depending on how you are doing it it's very important you save and load before these things are stated so like if you load your game and you have something that says

global.hats = 0 on a create event then it doesnt matter if you load it, the game will always switch whatever you load and change it to 0

So what this looks like is as follows
1. at the menu
2. push load
3. global.hats = 4
4. game starts
5 theres a create event it says global.hats = 0
6 so now when you start the game no matter what your hats are 0

I stress this with a lot of people, you must save all vars that are part of how your game runs not just some because thats when you run into errors. On one of my games I saved literally everything from buildings x y to the character and all of his stats and enemies I saved it all so it matched EXACTLY with where I left off because if the game was working BEFORE you saved and its identical then you cant have errors when you load an exact copy.
 
Last edited:
N

northlight

Guest
Have you tried using ini_read_string? at all?

What im trying to figure out is it should not load a random var it should load ONLY what you put in, you need to make a thing that saves right when you start a new game to have a frame to work from then you change a few things and save again and then exit out and reload the game to test if it truly works once you get it working right then you should be good

Lets say you start a game and then decide to save thats no problem
But it's the loading where you are having the problem something isnt right with it.
 

Vinsane

Member
Have you tried using ini_read_string? at all?

What im trying to figure out is it should not load a random var it should load ONLY what you put in, you need to make a thing that saves right when you start a new game to have a frame to work from then you change a few things and save again and then exit out and reload the game to test if it truly works once you get it working right then you should be good

Lets say you start a game and then decide to save thats no problem
But it's the loading where you are having the problem something isnt right with it.
Hey mate just letting you know that all is now well, everything is working as it should be.

Thank you so much for the help I really appreciate it.
 
Top