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

Windows How can you reset mutiple persistent rooms???

S

Strryker

Guest
Hey guys, I have a problem, I'm making a game like the mini clip game robokill where there are mutpile rooms in an area. my problem is that because the rooms need to be persistent, when you die I'm unable to properly program a proper room reset for multiple rooms. If some one has a way to reset multiple persistent roms at once please let me know asap. This game is so close to being finished and you can make it possible.

Thank you very much!
 
I don't have a direct answer for your question, but I do have some advice.

because the rooms need to be persistent,
I highly recommend NOT using room persistence. It would be much better to implement a simple save and load system. This will give you ultimate control over how you save the state of your room, what you save, and what you reset back to default. I have a tutorial on my youtube channel that would probably help you out.


You could use this system to track defeated enemies, destructible objects, and collected pick ups. And I'd be happy to answer any questions you may have about the system.
 
J

joakimFF

Guest
The above advice is solid, a less sexy way would be to iterate trough every room and reset them.

create a persistent controller object and put the below code in the room start event. then go to the first room.

if room_exists(room_next(room)) {room_persistent = false; room_goto_next();} else {room_goto(start_room); instance_destroy();}
 
S

Strryker

Guest
I don't have a direct answer for your question, but I do have some advice.


I highly recommend NOT using room persistence. It would be much better to implement a simple save and load system. This will give you ultimate control over how you save the state of your room, what you save, and what you reset back to default. I have a tutorial on my youtube channel that would probably help you out.


You could use this system to track defeated enemies, destructible objects, and collected pick ups. And I'd be happy to answer any questions you may have about the system.
Awesome, this works super well. just another question if you don't mind. so this shows me how to set up an illusion of persistent with objects that are initially created when the room is first initialized. but how about let's say I open a chest and then a sword is created. I want that sword to stay there when I come back to that room. what would be an effective way in doing that?

Thank you so much.
 
@Strryker Hmm, yeah that is a slightly more difficult problem. It could be considered a 'state" of the chest. The chest has 3 states: closed, open with sword there, and open with sword removed. Picking up the sword would set the state of the chest.

Another option, especially if you want to have randomly dropped items that aren't tied to a static object, is to create a similar system for "dropped" items in the room. This would be quite a bit more complex because you would need more than 1 value. You would need at minimum the x, y, and object index (the type of object it's an instance of). This is where things get REALLY complex, because you can no longer have one universal ds_map, you now need a series of data structures (either a grid, list of lists, or a map with maps in it). As you enter a room, you would look up the data structure that holds the dropped items in that room, loop through that structure and recreate all the items. When they are picked up, they find themselves in the same list and remove themselves. It is every bit as complex as it sounds. I would probably organize it like this:

  • ds_map "dropped_item_rooms"
    • One entry for each unique room visted
    • Key for each entry: room name <string>.
    • Value for each entry: ds_list
      • Each entry in the list is another list.
        • Each entry in the list is a list. One list per item on the ground.
          • The first entry in the list is the object_index for the item.
          • The second entry in the list is the X value.
          • The third entry in the list is the Y value

When you drop an item on the ground, it adds itself to the room's dropped item list.
If the item is picked up, it finds itself in the item list and removes itself.
At room start, find the list in the dropped_item_rooms ds map, loop through that list and create the objects in the correct locations.

Saving this data to a file is going to be a NIGHTMARE, though. You'll have to convert each data structure into a string using ds_<type>_write for saving and ds_<type>_read for loading.

[edit] Alternatively, you could have one giant ds_grid that has columns for the room name, the object index, the x and the y value. Then every time you enter a room you loop through the entire grid looking at items in the current room and spawn them. This would remove much of the complexity but may be a bit slower if you are dealing with enormous amounts of items.

Do I think there's probably a better way to handle this? Yes. There HAS to be. I can't imagine managing this much data for item volumes like you would have in Binding of Isaac... but I honestly can't think of a better way. The system I built is really built around static data points: objects that can be manipulated that were placed in the room, and hard coded values that you can change as the players progress through the game. Anything beyond that and it seems you are getting into some really, really challenging territory.
 
Top