auroraborealis
Member
Hi again! It's been a hot minute since I posted here. I'm having issues with loading health and score. For instance, if I go into a room, then a script I have runs to save the game. I have it save the current room, health and score. I tried making all the objects managing these persistent, then removing them from the other rooms and keeping them in one room so that the values carry over from room to room. Although, when I try to load the game, rooms that did not have the objects managing these so the health and score would not appear.
They also use global values (both being in the player). Should I try moving those variables from the player to the objects that manage the health and score? Or should I try a different approach?
Here's some of the code I use, just in case there's something wrong that I can't figure out.
If there is more code you need to have a look at to see what's wrong, I'll gladly provide some.
Thanks in advance!
They also use global values (both being in the player). Should I try moving those variables from the player to the objects that manage the health and score? Or should I try a different approach?
Here's some of the code I use, just in case there's something wrong that I can't figure out.
GML:
///Load file script
if (file_exists("save.sav"))
{
ini_open("save.sav");
var LoadedRoom = ini_read_real("save1","room",room0);
global.playerhp = ini_read_real("save1","playerhealth",100);
global.playerscore = ini_read_real("save1","playerscore",0);
ini_close();
room_goto(LoadedRoom);
}
else
{
//Do nothing
}
Code:
///Save file script
if (file_exists("save.sav")) file_delete("save.sav");
ini_open("save.sav");
var SavedRoom = room;
ini_write_real("save1","room",SavedRoom);
ini_write_real("save1","playerhealth",global.playerhp);
ini_write_real("save1","playerscore",global.playerscore);
ini_close();
Thanks in advance!