Windows Timer destryed objects

L

lexafram

Guest
So i recently got my code to work which spawned an object where i wanted by left clicking but i want to destroy if after a certain period of time, how could i do that?
Thanks a lot for your help
 

Datky

Member
In the create event, you make a "timer" variable, which is equal to 0.
In the step Event of the object, you write :
Code:
timer += 1;

if (timer >= xx) {
      instance_destroy();
}
xx is the time spent before the object gets destroyed.
 
L

lexafram

Guest
In the create event, you make a "timer" variable, which is equal to 0.
In the step Event of the object, you write :
Code:
timer += 1;

if (timer >= xx) {
      instance_destroy();
}
xx is the time spent before the object gets destroyed.
I created a timer var
"var timer = 0"
And put the code you generously showed me in my step event but it still makes an error appears sqying the var wasnt read in the step event before execuring the script
 
L

lexafram

Guest
Don't do "var timer = 0", juste "timer = 0".
i tried what you say and now, it doesn't seem to spawn in the object at all but when i delete the "
if (timer >= 02) {
instance_destroy();
}
"
part, it works again.
PS: how do i place 2 or more if statements in a row? is there a certain way to do it?
 
Top