SOLVED GameMaker2 (alarm[0]) Destroy Object

K

KaitoBrando

Guest
Hello I am new to creating games and I am making a weapon system in which it is destroyed after a certain time.

But I put an alarm[0] = with the command instance_destroy () more if I put alarm[0] = 1 the bullet is simply destroyed at the same time and if I put alarm[0] = 2 it is not destroyed in any way.

Would anyone have a method of solving this problem?



if my english is bad and why i am using google translator.
 

Freddy Jones

Your Main Detective
Something tells me if it's working with 1 but not 2 you're setting the alarm in something like a step event and you keep setting it back to 2 before it can activate the alarm. The reason it would work with 1 is because the alarm will work when it hits 0 but not when it hits 1....

Please post your code that contains the alarm setting and the event it is in
 
K

KaitoBrando

Guest
Something tells me if it's working with 1 but not 2 you're setting the alarm in something like a step event and you keep setting it back to 2 before it can activate the alarm. The reason it would work with 1 is because the alarm will work when it hits 0 but not when it hits 1....

Please post your code that contains the alarm setting and the event it is in
Here

Codes of Bullet:


Codes for Spawn Bullets:

 

Freddy Jones

Your Main Detective
Which events?
He posted pictures. The problem is that he has alarm [0]=2; in his step event.

If you want your bullet object to be destroyed a certain amount of time after it is created, you should set the alarm in the Create Event.
He could also just set the alarm right after instantiating it. But I agree with you for his case.


@KaitoBrando The problem you're having is that you set your alarm to 2 steps inside of the step event. It will never destroy your bullet because it keeps getting set back to 2 before it ever reaches zero.

The reason you saw that it worked when it was set to 1 was because every step the alarm value gets reduced by 1. Since 1 reduced by 1 is zero, your alarm event will fire before the step event sets it back to 1, like it does with 2.


So like we suggested: move your alarm[0]=2 to the create event.
 
K

KaitoBrando

Guest
He posted pictures. The problem is that he has alarm [0]=2; in his step event.


He could also just set the alarm right after instantiating it. But I agree with you for his case.


@KaitoBrando The problem you're having is that you set your alarm to 2 steps inside of the step event. It will never destroy your bullet because it keeps getting set back to 2 before it ever reaches zero.

The reason you saw that it worked when it was set to 1 was because every step the alarm value gets reduced by 1. Since 1 reduced by 1 is zero, your alarm event will fire before the step event sets it back to 1, like it does with 2.


So like we suggested: move your alarm[0]=2 to the create event.
Thank you worked perfectly.
 
Top