Legacy GM Setting room_persistent from another room

C

Catonator

Guest
I'll get straight to the point: my game has a load of objects with loads of variables I want to save (basically like Hotline Miami, where it saves the weapons, enemy bodies and whatnot). I didn't want to create huge global arrays for this, so instead I set the room_persistent to 1 to save these various objects. Now the issue is this: once I leave the level, the rooms are going to stay in memory. Let's say the player plays multiple levels in a row, which means that the framerate will drop slowly and eventually the game will run out of memory and crash.

I want to set the rooms to not be persistent once I finish the level. How can I set the room persistence to false outside the room which I'm currently in, without leaving the room?

Thanks in advance.
 
J

joakimFF

Guest
You cant set the persistence for a room your not in, you either have to loop trough all the rooms you want to reset, or completely skip room persistence and instead control persistent object by storing them in a ds_list/array which in my opinion is the way to go. its more work but gives you full control.
 
C

Catonator

Guest
I assume that by "looping through the rooms" you mean actually going there and setting room_persistent to false. If that is the case, then that's too bad, since I actually can't do that or the game will crash. I guess I have to live with the memory leak then.
 

MaxRock

Member
room_persistent variable rather won't help here, so how about using the room_set_persistent(ind, val) function? From the manual: "With this function you can change (or set) the persistence of any room in your game except the current one."
 
J

joakimFF

Guest
NOTE: This function will NOT work to switch off persistence if the room has already been visited! A persistent room, once visited, is held in memory and to switch off persistence you should go to that room and set the room_persistent variable to false and then exit the room again.



what you can do is create a persistent controller object and put the below code in the room start event, and also have a global variable lets say global.resetting = true;. then go to the first room.

Code:
if room_exists(room_next(room)) {room_persistent = false; room_goto_next();} else {room_goto(start_room); global.resetting = false; instance_destroy();}

Then to stop the game from executing code while looping put

Code:
if global.resetting { exit; }
in the top of all objects room start events
 
C

Catonator

Guest
Thanks for the help. Unfortunately your solution doesn't seem to work, as the game just goes into an infinite loop and starts filling up memory.
 
Top