J
jamie_simpson
Guest
I've noticed that now ._.If this code works when using instance_id like that, that's a coincidence at best and wrong at worst.
instance_id is (to quote the manual) a read only array (which) holds all the ids of every active instance within the room.
This could work if you're using a version of GameMaker that refers to the first index of an array when used in variable context and the instance in question happens to be the first one. In all other cases, this will either destroy the wrong instance or crash.
id refers to the instance that is under the current execution scope.
self used to be equivalent to the value -1, which was interpreted as equivalent to id in some functions. Now, it is equivalent to id.
An object's name does not refer to the calling instance, but either to the first instance of an object in a reading context, or to all instances of an object in a writing context. If an object ID is interpreted as the instance you meant to refer to, it is either because that instance is the only instance of that object, or a sheer coincidence.
Use id. Or, better yet, just call instance_destroy() without any arguments - then it will automatically apply to itself.
i thought that it worked for me because when a bullet collided with an enemy, not all of the bullets got destroyed (like they did before)
what i didn't notice is that the bullet that hit the enemy didn't get destroyed either and i probably passed a blind eye on that because some of my gun types have bullet penetration.
and also, I've tried all these three as arguments for instance_destroy();
- (self);
- (bulletO);
-(id);
-();
but none of them worked hence why i got so exited when i tried instance_id;
here is my current code for dealing with the bullet and destroying it
bulletO --> step -->
Code:
if (x < 0) or (x > room_width) or (y < 0) or (y > room_height)
{
instance_destroy(id);
}
if (penetration = 0) or (penetration < 0)
{
instance_destroy(id);
}
any suggestions as to why it doesn't work?