Chaser
Member
Im a bit baffled as to why my code isn't working as i think it should, think i have got my code the wrong way round or what not, so could someone look at this and enlighten me.
Basically an object is pushed into a 'Zone', which is the margin of an object, whilst the object is in this zone i want to create an instance:
step event
if (place_meeting(x,y,instance1))
{ instance_create(x,y,instance2}
if (!place_meeting(x,y,instance1) && (instance_exists(instance2)
{
with(instance2)
{
instance_destroy()
}
^^ this seems to work fine, but because its in the step event i don't want it to keep creating the instance every second so i amended the code to read this:
if (place_meeting(x,y,instance1))
{
if (!instance_exists(obj_instance2)
{
instance_create(x,y,instance2}
}
}
if (!place_meeting(x,y,instance1) && (instance_exists(instance2)
{
with(instance2)
{
instance_destroy()
}
So, whats happening now is as soon as the instance2 is created it is destroyed. I just cant figure it out as to why its doing it, im clearly missing something, in my head its, hey when this collision happens and this object isn't there, then created it, and if the collision isn't happening anymore but the object remains then get rid of it.
sorry for my stupidness, but i need help.
Basically an object is pushed into a 'Zone', which is the margin of an object, whilst the object is in this zone i want to create an instance:
step event
if (place_meeting(x,y,instance1))
{ instance_create(x,y,instance2}
if (!place_meeting(x,y,instance1) && (instance_exists(instance2)
{
with(instance2)
{
instance_destroy()
}
^^ this seems to work fine, but because its in the step event i don't want it to keep creating the instance every second so i amended the code to read this:
if (place_meeting(x,y,instance1))
{
if (!instance_exists(obj_instance2)
{
instance_create(x,y,instance2}
}
}
if (!place_meeting(x,y,instance1) && (instance_exists(instance2)
{
with(instance2)
{
instance_destroy()
}
So, whats happening now is as soon as the instance2 is created it is destroyed. I just cant figure it out as to why its doing it, im clearly missing something, in my head its, hey when this collision happens and this object isn't there, then created it, and if the collision isn't happening anymore but the object remains then get rid of it.
sorry for my stupidness, but i need help.
Attachments
-
132.8 KB Views: 6