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

GML Visual Is there a way to make something create an instance of something only if another kind of instance doesn't exist?

J

Jcraft2000

Guest
Basically I have a door switch. This door switch has an on and off version of itself which is integral to how the door function works. It also changes itself into an on or off version of itself respectively. This is all well and good, but I discovered a problem with my idea for this button: It is an app on a phone. So I have made an object that creates this door button app if the phone exists, what I didn't anticipate is that it would re-creates it once that off button instance changes itself into the on button instance, leaving me with a constantly opening and closing door. Is there a way I can make it so that the Instance of the off button is created if the instance of the phone exists, but only so long as the instance of the on button doesn't also exist? DnD
 
Use the instance_exists function to check if an instance exists of something.
Code:
if (instance_exists(phone) && !instance_exists(on_button)) {
   instance_create_layer(x,y,layer,door);
}
 
J

Jcraft2000

Guest
Okay I am afraid of code so i tinkered around a bit, and I don't know if this will have negative side effects later but for now what worked for me was to assign the door button app to its own object which creates it, the prefix the creation drag and drops with a drag and drop sequence essentially amounting to "If Instance Exists: oDoor_Button_On, then Destroy Instance: oDoor_Button_Off. Else:"
 
Top