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

[SOLVED] My save / load is putting my character in random places - .ini

C

Crispywrists

Guest
Hello!

So I've just got round to implementing a load and save feature, but it's giving me a bit of trouble.

I want it to remember my character's (obj_cliff) position and load that up, but whenever I load it it spawns at a random place. I mean if I press save somewhere then load it, it will always load it at that random place, so it is saving a position, just the wrong one...Then if I save it again in a different place it will load up at the new seemingly random location. Rest assured it is driving me mad.

Here's my save script:

if (file_exists("save"))file_delete("save");
ini_open("save");
var savedroom = room;

// The room
ini_write_real("save1","room",savedroom);

//Cliff's posish
ini_write_real("save1","position",obj_cliff.x);
ini_write_real("save1","position",obj_cliff.y);

// Inventory
ini_write_real("save1","inventory", global.inv);
ini_write_real("save1","inventory", global.key);
ini_write_real("save1","inventory", global.skateboard);
ini_write_real("save1","inventory", global.docmartens);
ini_write_real("save1","inventory", global.cash);
ini_write_real("save1","inventory", global.bones);
ini_write_real("save1","inventory", global.snacks);
ini_write_real("save1","inventory", global.phone);

//Others

ini_write_real("save1","others", global.cool);
ini_write_real("save1","others", global.scenehappened);
ini_write_real("save1","others", global.rimesley);

//Bowling backroom

ini_write_real("save1","others", global.bowling);

ini_close();

Then my load script:

if (file_exists("save"))
{
ini_open("save");
var loadedroom = ini_read_real("save1","room",rm_initialize);

//Cliff's position

obj_cliff.x = ini_read_real("save1","position",-1);
obj_cliff.y = ini_read_real("save1","position",-1);

//Inventory
global.inv = ini_read_real("save1","inventory",0);
global.key = ini_read_real("save1","inventory",0);
global.skateboard = ini_read_real("save1","inventory",0);
global.docmartens = ini_read_real("save1","inventory",0);
global.cash = ini_read_real("save1","inventory",0);
global.bones = ini_read_real("save1","inventory",0);
global.snacks = ini_read_real("save1","inventory",0);
global.phone = ini_read_real("save1","inventory",0);

//Others

global.cool = ini_read_real("save1","others",0);
global.scenehappened = ini_read_real("save1","others",0);
global.rimesley = ini_read_real("save1","others",0);
global.bowling = ini_read_real("save1","others",0);

room_goto(loadedroom);
}


Is there any glaringly obvious faults? Because my inventory is playing up as well, but that may just be to do with how I've set it up (I admit it, I'm a noob), I'm not even sure I've got all my global variables in that save - but I tried removing all else apart from the basic position save / load functions and it still goes weird.

On a second note is there an easy way to view all global variables you have in your game to make sure they're saved?

Many thanks in advance and sorry for the long code.

Crisps.
 

kamiyasi

Member
The "key" section in ini_read_real searches for a section of the .ini to read from. In your code, both x and y are looking for something called "position" and so they are both returning the part of the ini where you saved the x position of your character. You should instead name them something like positionx and positiony.
 
C

Crispywrists

Guest
Amazing, that worked like a treat - thank you!

Does the same apply for the items in my inventory? Would I need to rename each slot like "Inventory1", "Inventory2" etc etc? Or is it just because there was a clash in names?
 
C

Crispywrists

Guest
Amazing, that worked like a treat - thank you!

Does the same apply for the items in my inventory? Would I need to rename each slot like "Inventory1", "Inventory2" etc etc? Or is it just because there was a clash in names?

After a few quick checks, it does! This simple bit of info has fixed all my save / load troubles - You are my hero.

Thanks very much and enjoy your day.
 
Top