How to destrory old instance if a new instance is created?

M

Matthew Imamura

Guest
So basically I want to destroy the 1st instance if a 2nd one is created.
here are the current codes I have:

Code:
if (instance_number(obj_activetrail) > maxobject)
{
     with (instance_find(obj_activetrail, maxobject))
     {
           instance_destroy();
     }
}
But instead of destroying the 1st one, it is destroying the new ones that are being made.

is there anything i can use to destroy the 1st instance if a new instance is created?
any help would be much appreciated, thank you for your time :)
 

FrostyCat

Member
It worked! thank you so much!
but if you can, can you please explain to me how it worked?
The Manual's entry on instance_find() tells you why it worked.
The Manual's entry on instance_find() said:
Syntax:
Code:
instance_find(obj, n)
obj: The object to find the nth instance of
n: The number of the instance to find.
Putting a 0 in the position you were shown means finding the first instance of the object.
 

obscene

Member
thank you. I think i understand it a bit. i'll just have to read and practice more.
Basically, any time you are working with a data structure in GM, like a list or even an array, counting begins at 0. A list with 3 positions would be numbered 0,1,2. The first position is 0. Similarly, the first frame of an animation is 0. The beginning position of an audio sample is 0. To go to the first room in your game, the code would be room_goto(0). So just the same, when you get the list of instances of an object, the first one will be 0.
 
M

Matthew Imamura

Guest
Basically, any time you are working with a data structure in GM, like a list or even an array, counting begins at 0. A list with 3 positions would be numbered 0,1,2. The first position is 0. Similarly, the first frame of an animation is 0. The beginning position of an audio sample is 0. To go to the first room in your game, the code would be room_goto(0). So just the same, when you get the list of instances of an object, the first one will be 0.
Now it makes total sense. thank you!
 
Top