Whats wrong with this code?

V

veko

Guest
Hello, this code isnt working (there are no errors etc, its just not working) any idea why?
CODE
STEP EVENT:
with obj_pickup1
{
if instance_count < 1
{
with self
{
instance_destroy();
}
}
}
 
H

Heropants

Guest
I'm not 100% sure what you're trying to do. I'm assuming you want to a specific instance to destroy itself when if there aren't any obj_pickup1 objects in the game.

First off, instance_count counts all the instances in the game (including the object using the code). Therefore, it's impossible for this code to run and still have instance_count = 0 (since the object must exists to run the code but if the object does exists then instance_count can't be 0).

What you probably want to do is use instance_number. This function checks how many of a specific number of objects are in the room (that are not deactivated).

So in your object that you want to be destroyed, do this:

STEP EVENT:
if instance_number(obj_pickup1) = 0
{
instance_destroy();
}

I believe that's what you're trying to do anyways.
 
N

Neo

Guest
Try this
Step event
if !instance_exists(obj_pickup1)
{
instance_destroy(); // I assume you are trying to destroy the object of this code so you dont need self
}
 
V

veko

Guest
Try this
Step event
if !instance_exists(obj_pickup1)
{
instance_destroy(); // I assume you are trying to destroy the object of this code so you dont need self
}
Try this
Step event
if !instance_exists(obj_pickup1)
{
instance_destroy(); // I assume you are trying to destroy the object of this code so you dont need self
}
Thats exactly what i needed, thank you so much!
 
Top