continue the alarm

kbessaGui

Member
I made this code for when the player was on the platform at a certain time the platform would no longer exist, but it only ceases to exist if I stay on it I wanted to know how to continue the alarm even if the player is no longer on it

in obj that will be destroyed

on step event:
GML:
if (!place_meeting (x, y-1, oPlayer_1))
{
alarm[0]=30
}
on alarm 0
instance_destroy()[




a doubt

you don't need to explain but there is a thing that I didn't understand is the need to have the "!" on line (!place_meeting for it to work since in my logic it would not need it. I think it got confused here

the main idea is to make an object that if the player is on top it will trigger an alarm and after a while it will destroy itself
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
OKay, the ! symbol means "not", so in this case, what's happening is that if there is NOT a collision with the player, then the alarm is being set every step of the game, while if there IS a collision with the player, the alarm is not being set and so counts down. This is why the alarm only works if the player stays on the platform. To make it work with a single collision you'll need to use a variable, for example:

GML:
// CREATE EVENT
destroy = false;

// STEP EVENT
if !destroy /// Literally "if not destroy", which is the same as saying "if destroy is not true"
{
if (place_meeting (x, y-1, oPlayer_1))
    {
    destroy = true;
    alarm[0] = 30;
    }
}
Here the "destroy" variable will control whether or not to the platform should be destroyed or not, and only set the alarm once when the player lands on it.
 

kbessaGui

Member
OKay, the ! symbol means "not", so in this case, what's happening is that if there is NOT a collision with the player, then the alarm is being set every step of the game, while if there IS a collision with the player, the alarm is not being set and so counts down. This is why the alarm only works if the player stays on the platform. To make it work with a single collision you'll need to use a variable, for example:

GML:
// CREATE EVENT
destroy = false;

// STEP EVENT
if !destroy /// Literally "if not destroy", which is the same as saying "if destroy is not true"
{
if (place_meeting (x, y-1, oPlayer_1))
    {
    destroy = true;
    alarm[0] = 30;
    }
}
Here the "destroy" variable will control whether or not to the platform should be destroyed or not, and only set the alarm once when the player lands on it.
I understood the " ! " function, and also the variable that makes the alarm continue after just one collision, Thank you
 

Foldup

Member
I would say that you need to have an escape clause on that alarm to make sure it's not already running.

if alarm[0]<0
alarm[0] = 30

The other thing you probably need is to add a variable for whether it's been triggered yet or not.
 
Top