Legacy GM Distinguishing room_created vs dynamically created instances? (Saving/Loading GML)

Dr_Nomz

Member
I cannot even begin to describe how difficult it is just to save and load things, it's even WORSE when you can either spawn in items endlessly because the room editor creates them, or it deletes everything instead of just the room_editor items.

Basically I just need to know if there's some way I can tell my code to treat room_created objects differently than dynamically created ones, so the first time a room object is picked up, it no longer spawns every time the room starts. At the same time, I need it to understand that an item not created in the room editor should behave differently.

So is there a way to do this?
 

samspade

Member
I cannot even begin to describe how difficult it is just to save and load things, it's even WORSE when you can either spawn in items endlessly because the room editor creates them, or it deletes everything instead of just the room_editor items.

Basically I just need to know if there's some way I can tell my code to treat room_created objects differently than dynamically created ones, so the first time a room object is picked up, it no longer spawns every time the room starts. At the same time, I need it to understand that an item not created in the room editor should behave differently.

So is there a way to do this?
Simplest way would be to have all objects that this matters for have a variable which is set to false and then go into the creation code of those objects that are placed in the room editor and change it to true. Or vice versa. Then check that variable when you want to distinguish between them.

But it seems like you're conflating two problems. The the problem of not respawning an object once you picked it up is different. For that you need some type of global or persistent variable. It should hold a true false variable. The room object can then have creation code that destroys itself depending upon the state of the variable.
 

TheouAegis

Member
To prevent a room object from reappearing after it has been picked up, you need to set a global variable and in that object's Room Start event destroy it if that variable is set. Save that variable to a file to prevent tge item from respawning across play sessions. Room created objects have access to the incense creation code, so taking advantage of that is about the only way you can tell the game if an object was created dynamically or not.
 

Dr_Nomz

Member
Great, well can someone show me an example of how they did it? Because I've been stuck trying to use variables to differentiate them and I can't get it to work.
 

samspade

Member
Great, well can someone show me an example of how they did it? Because I've been stuck trying to use variables to differentiate them and I can't get it to work.
Code:
///create event
created_in_room = false;
When that object is placed in the room editor, go to instance creation code and type:

Code:
created_in_room = true;
Then an example use:

Code:
with (obj_some_object) {
    if (created_in_room == true) {
        //do what you want
    }
}
 
Top