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

How to save a room state?

C

CXXXV

Guest
Say in my room1 i have object1 at (10,10), then i move it to (10,15).

How do i make my object1 stay at (10,15) after i change room and back?
 

Xer0botXer0

Senpai
Enable the objects persistence checkbox.



The alternative suggested by Nocturne assumes that you delete the instance when leaving the room, there are benefits to this.

one benefit is closing the game then coming back to it. like real time save/load function!
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
Store the position in a file. Easiest is to store the object and the position to an ini file, but you can also use text files, binary files, buffers, or ds_maps.

So, an example would be:

Code:
ini_open("Save.ini");
ini_write_string("object_info", "object", object_get_name(OBJECT_TO_SAVE));
ini_write_real("object_info", "x", x);
ini_write_real("object_info", "y", y);
ini_close();
You would then use something like the following:

Code:
ini_open("Save.ini");
var obj = ini_read_string("object_info", "object", "");
var xx = ini_read_real("object_info", "x", 0);
var yy = ini_read_real("object_info", "y", 0);
if obj != ""
{
switch(obj)
    {
    case "obj_Player": instance_create(xx, yy, obj_Player); break;
    // add more cases for each object
    }
}
The benefit of this over persistence is that you don't need to worry about the instance being "carried over" to the wrong rooms, and you can also close and restart the game and the position will still be saved.
 
C

CXXXV

Guest
Enable the objects persistence checkbox.



The alternative suggested by Nocturne assumes that you delete the instance when leaving the room, there are benefits to this.

one benefit is closing the game then coming back to it. like real time save/load function!
But if i use persistent the object would appear in the next room no?

Store the position in a file. Easiest is to store the object and the position to an ini file, but you can also use text files, binary files, buffers, or ds_maps.

The benefit of this over persistence is that you don't need to worry about the instance being "carried over" to the wrong rooms, and you can also close and restart the game and the position will still be saved.
I have to do the hard work eh. How do i iterate all object in my room?
 
A

Aura

Guest
If you want the room's state to remain as-is after returning from another room, use room persistence instead of object persistence. Go to the Settings tab and check the Persistent checkbox. Or alternatively use room_persistent.

To loop through all the instances in a room, you'd use the all keyword.

Code:
with (all) {
   //Do something
}
You could try experimenting with game_save() and game_load() as well:

http://docs.yoyogames.com/source/dadiospice/002_reference/miscellaneous/game_save.html

http://docs.yoyogames.com/source/dadiospice/002_reference/miscellaneous/game_load.html
 
C

CXXXV

Guest
If you want the room's state to remain as-is after returning from another room, use room persistence instead of object persistence. Go to the Settings tab and check the Persistent checkbox. Or alternatively use room_persistent.
What's the downside with room_persistent?
 

Xer0botXer0

Senpai
I can imagine the up side is that while your game is running when you go to another room what ever is in the previous room will remain where it is, I dont know how that works(how well it's optimized). And then on the contrary the downside depends on the type of game you're making, do you need to save/load rooms ?

Like if you're playing a platformer with stages, if there's ever the need to head back in a direction while all the monsters are already dead so you can collect their drop because your inventory was full, so you had to go to a shop further east to trade then return west to collect more loot, It all depends on how you want to play your game, if there is that need then room persistent would work, but save/load caters for the player exiting the game while the loot's just hovering above the dead enemy bodies, if the player exits the game and returns what will that area look like ? are the dead bodies still there, is the loot still there, or if you revisit the area do they just respawn so you have to kill the monsters again ?

In my case room persistence is a must, im working on a multiplayer game so when there's a house in that area, it must be there when someone goes there, even after restart. So if you get room persistence, then you need to decide do you want to save that data for the next time the player plays again.
 
D

Disarmed97

Guest
So if I were trying to save my character's place in a room so that there still there when I get back should I do something like this?

file_delete("The Place You are game quick save file")
game_save("The Place You are game quick save file");

ini_open("Save.ini");
ini_write_string("character_info", "character", object_get_name(main_character));
ini_write_real("character_info", "x", x);
ini_write_real("character_info", "y", y);
ini_close();
 
B

Bence Monori

Guest
I have a pretty bad issue whit save_game() load_game() . First thing what all you have to know, im making a game what turn based strategy with tons of stats and multiple objects, room also with different positions. I know if i try to save everyting whit the txt_read_write stuff is it bin or ini, i have to list every micro varriable to a save state. So its more easy to use game_save, game_load ( i have my own engine to load included files after close the game and restart it and load so its not cause problem)
Anyway, the main problem is, my exe only save and load on my own computer but non anyone's else. Txt based saved stats are saved to the appdata location but there are no sav or ini files nowhere. Im gonna get mad beacuse this is a 3.5 years old project and if i cant put any precise saving system in it, all the game contents and options are useless. Tbs like Homm is a pretty long game, imagine you cant save your states... I know this is out of topic, but somebody help me and explain me what did i wrong!
 

Attachments

TheWaffle

Member
If you are trying to do this as an HTML, you are SOL. JS pretty much blocks all file read-writes for security issues. For others (windows), its a sandbox thing. Basically, you need a few dummy files saved or included with the project. When your projects saves a newer version, this goes into the sandbox that can be accessed later. This all works, other above have explain this already, but did not mention the sand-box thing. The challenging part here is finding the full path to the sand-box. By having a few dummy files, your game can find this out, and test for it. Hope this helps.
 
Top