• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

Saving using a ini file [solved]

P

powernoel

Guest
Hi everyone!
I have been using Game Maker Studio Pro (1) for a bit long now, and after reading lots of thread here's my first one!

I'm coding a save system for my game. I use a ini file system, with an [object] section to store the amount of each object the player has while saving.
During the game, the amount of each item is stored in "obj_cursor" in a 2D list.
For exemple, getting 10 "saphir" (wich is indexed by 5), is stored in obj_cursor.loot[5,0]

Here's how I load the save : obj_cursor.loot[5,0]=ini_read_real("objets","saphir",0)
And how I save : ini_write_real("objets","saphir",obj_cursor.loot[5,0])

When I manually edit the .ini in the local storage (getting 20 saphir for exemple), I have my 20 saphir in my bag when the game launch and during the whole game. But when I save, the new ini file set [objets] "saphir" to 0.

It's really strange because the x and y coordonate of my character, which are saved too, are workng well.

By coding a debug message, I've seen that when my room start, obj_cursor[5,0] is equal to 0 and then 10 (I have two lines of degug while having one line of debug's code).

Here's the full saving system:
if file_exists("rockman.sav")
{
file_delete("rockman.sav")
}
ini_open("rockman.sav")
ini_write_real("position","x",obj_player_world.x)
ini_write_real("position","y",obj_player_world.y)
ini_write_real("objets","saphir",obj_cursor.loot[5,0])
ini_close()

And the full loading system:
if file_exists("rockman.sav")
{
ini_open("rockman.sav")
x=ini_read_real("position","x",x)
y=ini_read_real("position","y",y)
obj_cursor.loot[5,0]=ini_read_real("objets","saphir",0)
ini_close()
}

I hope you'll help me as you helped the other threads I've been reading all this time!
And sorry for the english, I'm French. Feel free to correct me if I wrote grammatical mistakes, it helps me too ^^"
 
Last edited by a moderator:

Rob

Member
At first I thought it was because "objets" should be "objects" but you spelled it the same way in both save/load so that's not the issue.

How many obj_cursors do you have and is one of them created after you load the save file?

That object might be overwriting your save. (Or whatever object sets saphir could be overwriting it).

If you can see that the value for saphir is correct in your .ini file then that's likely your problem.
 
P

powernoel

Guest
I have only one instance of obj_cursor, created before I load the file.
It's persistant so I when I change rooms it should be re-created so that's not the issue neither.
I checked and the value is overwritten when I save, but not when the game launch. That's really weird because during the game, I have my saphires.

I'll try to fix the obj_cursor variables on global variables. I don't know if it might solve the problem...

[EDIT] I switched all the saved variables on global storage, now everything work fine.
It does not explain some weird problem, but they're solved now. Thanks :)
 
Last edited by a moderator:
Top