Legacy GM how do i save players x,y coords? (.ini file saving)

Le_Beholder

Member
Hello, I've finally figured out how to implement saving by ini file writing into my game, now im running into what i hope is the last hurdles in that effort.
so far I can save how many hearts the player has, how many bombs hes got, and how big his health is.
what im now trying to do is save the exact x and y coordinate of the room hes in at the moment of saving, and then having actually appear there upon load.
so far all ive got is
Code:
global.Xpos = obj_player.x;
global.Ypos = obj_player.y;
just as the players create event variable setup,
Code:
ini_write_real('save1','Xpos',global.Xpos);
global.Xpos = ini_read_real('save1','Xpos',global.Xpos)

ini_write_real('save1','Ypos',global.Ypos);
global.Ypos = ini_read_real('save1','Ypos',global.Ypos)
saving what i think those values should be,
Code:
global.Xpos = ini_read_real('save1','Xpos',global.Xpos)
global.Ypos = ini_read_real('save1','Ypos',global.Ypos)
and that for loading.
all i can think of so far is somehow having the player jump_to_point global.Ypos and global.Xpos, after the game control object check whether global.loading is set to true.
(which global.loading is also used in the games first room, the title menu screen to load the game only after switching rooms to the main game one where the saving takes place. if that makes sense..)

any thoughts? thanks in advance..

EDIT:
i solved it lol.
Code:
if global.loading = true
{

load_game();
obj_player.x = global.Xpos;
obj_player.y = global.Ypos;
global.loading = false;
}
else
{
global.loading = false;
}
 
Last edited:

Yal

šŸ§ *penguin noises*
GMC Elder
The variables for an instance's x and y position are literally called x and y, can't you just set those directly?

When loading a different room, it's a bit trickier, but you could set a global variable "currently_loading" to true when loading the file, and if it's set, the player sets its x to global.xpos and its y to global.ypos in the Create event, no matter where originally created in the room. (And then sets currently_loading to false so you won't jump to the saved coordinates each time you clear a level or go through a door)
 

FrostyCat

Redemption Seeker
Code:
global.Xpos = obj_player.x;
global.Ypos = obj_player.y;
just as the players create event variable setup,
Code:
ini_write_real('save1','Xpos',global.Xpos);
global.Xpos = ini_read_real('save1','Xpos',global.Xpos)

ini_write_real('save1','Ypos',global.Ypos);
global.Ypos = ini_read_real('save1','Ypos',global.Ypos)
saving what i think those values should be,
You have the wrong idea about how variable assignments work. If you had the right idea, that setup should not have made any sense to you.

When you do this:
Code:
global.Xpos = obj_player.x;
You are NOT binding global.Xpos to the expression obj_player.x. This takes the value of obj_player.x at that point in time only and puts it into global.Xpos. Future updates to obj_player.x will NOT update global.Xpos.

If your intent is to write the actual current value of obj_player.x, your writing code should have looked like this:
Code:
ini_write_real("save1", "Xpos", obj_player.x);
global.Xpos = obj_player.x;
Contrast this with your attempt to write a variable into an INI field and then read that exact same value back into the exact same variable.

At this point, I think you should put a hold on game development. Every single question you asked reflects a bad grasp of programming basics --- how variable assignments work, how code runs sequentially, how data is organized. Get that sorted first before you continue, and if this means learning a more traditional programming language, so be it.
 
Top