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

Should be simple - Position_Meeting

K

KevDoesArt

Guest
Anyone know a quick script for making an obj appear (or even alpha in, right now I am using instance_create...) when the character goes to a certain coords (x,y) and then disappears at different coords with it it creating multiple duplication's of itself at the first coords. Basically appear and disappear when the player walks past but if you hit the coords more than once while the obj is there it doesn't create more of them.
 

makas

Member
if you dont want to create more of them just ad a flag at the "spawner" object, when collide with the player, set a variable called something like AlreadyCreated=false, on the create event of the object that spawn you object, in the collision event add:

Code:
if AlreadyCreated==false
   {
   instance_create(x,y,obj_player);
   Already_Created=true
   }
this way the next time you have that collision it wont spawn a new object just the fist time
 
A

Aura

Guest
You can use a variable that is set to true only once per condition. Create the instance when it's true, then set it to false. Once the condition is false, set the variable back to true, so that an instance can be created again.

Code:
if (place_meeting(x, y, obj_Spawner)) {
   if (can_create) {
      instance_create(x, y, obj_Bud);
      can_create = false;
   }
}
else {
   with (obj_Bud) {
      instance_destroy();
   }
   can_create = true;
}
 

TheouAegis

Member
Format of any spawner:

Initialize a variable that says the spawner has spawned anything.
Check if the criteria for spawning something have been met.
Check if the variable that says the spawner has spawned anything is not too high.
Spawn the thing the spawner was meant to spawn.
Set a variable in the thing that was spawned to remember what spawner spawned it.
Increase the variable that says the spawner has spawned anything.
Check if the spawner is too far off-screen and deactivate the spawner if it is.

...
When the thing that has been spawned is destroyed, decrease the variable in the spawner that spawned it that says the spawner that spawned it has spawned something.
 
K

KevDoesArt

Guest
You can use a variable that is set to true only once per condition. Create the instance when it's true, then set it to false. Once the condition is false, set the variable back to true, so that an instance can be created again.

Code:
if (place_meeting(x, y, obj_Spawner)) {
   if (can_create) {
      instance_create(x, y, obj_Bud);
      can_create = false;
   }
}
else {
   with (obj_Bud) {
      instance_destroy();
   }
   can_create = true;
}
This works but destroys the object when the player is not at place meeting. I need the object to stay, only destroy when at a diff place meeting and come back when at the first place meeting.
 
K

KevDoesArt

Guest
if you dont want to create more of them just ad a flag at the "spawner" object, when collide with the player, set a variable called something like AlreadyCreated=false, on the create event of the object that spawn you object, in the collision event add:

Code:
if AlreadyCreated==false
   {
   instance_create(x,y,obj_player);
   Already_Created=true
   }
this way the next time you have that collision it wont spawn a new object just the fist time
Hmmm, this is too simplistic. I need the object destroyed when at a diff place meeting and the turned back to false so that it can be recreated again.
 
K

KevDoesArt

Guest
MAKESHIFT SOLUTION:

I skipped the variables idea and created an instance_destroy in both the creation and destroy scripts so basically they looped. The light turns on and destroys the spawner after it creates the trigger to turn it off and the trigger to turn it off destroys itself after creating the trigger to turn it back on. That worked. It's dirty but functional.

Thanks everyone for your help!
 
Last edited by a moderator:
Top