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

Open World Save / Load

G

Greg5000

Guest
I've been developing an open world game with one large room and a main menu. My room has multiple NPCs in it and so far I have used room persistence effectively to be able to quit the game to the main menu and continue from there, however I have recently implemented a simple save and load feature using INI files so I can stop using persistence and allow players to quit the game and load later.

I've figured out how to save and load variables to my INI such as player position etc. this is simple enough, but I can't get my head around how to save the positions of all NPCs and re-create them where they were when the room is re-entered. To complicate things further the player and each of the NPCs also have paths assigned which should be resumed on loading the INI.

How do you write each NPC's x and y coordinates and path to the INI and get the NPCs to be recreated in the correct positions with the associated paths re-assigned when loading the game? In essence it seems like such a basic thing to be able to do but it seems horribly complicated.

P.S. I've already tried out game_save and game_load, they didn't work for me, caused the game to crash and got too complicated trying to work around it's limitations.
 

Gamerev147

Member
First off, never use game_save and game_load. They suck and are NOT professional. I would also recommend taking a look into these videos:

I know those videos are a bit long, but they are very professional and will work for almost any type of game.

Another things you could try is using the same code to save the X and Y for the player. For example:
When the saving mechanism is activated, have the NPC's execute a script. Then in this script have something like this:
Code:
///Save the NPC's location
if (file_exists("npc_loc.ini")) ini_open("npc_loc.ini")
ini_write_real("location", "x", x);
ini_write_real("location", "y", y);
ini_close();
The same goes for loading. If this doesn't work, just check out the videos. I'm sure they'll help.
Good luck!:)
 
Last edited:
G

Greg5000

Guest
Thanks for that I'll give them a watch, might be better than what I've done for now.. I have decided to try out a ds_grid to store the NPC object types, location etc.

When I save the game it uses the "with" function to loop through every NPC instance in the room (using a parent object) and writes the object type, coordinates and destination coordinates to a ds_grid. This grid can then be written to the INI and when the INI is read this grid data can be re-loaded and the NPCs can then be recreated as the correct type in the correct places and the paths can be recreated to the destination coordinates written in the grid. It's simple and seems to work well.. and if I add a new type of NPC all I have to do is make sure it is a child object of the NPC parent, in fact it doesn't just have to be NPC's, any object which I need to be recreated in the room simply needs to be a child of this object.
 
Top