GML Visual How can I make an event play only once on a repeating event?

B

bebesnuggles

Guest
The problem I'm having is when an object hits its target object, I want it to increase a score count, but only by one. However, no matter what I do, the count will go up by 7-12 points in an instant. I've tried moving the object away from the target immediately, but that doesn't really solve anything. What would yall recommend?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Personally, I use a combination of an alarm and a variable. You set the variable in the collision as well as the alarm, then in the alarm the variable is reset. The cool thing about this is that you make sure to set the alarm constantly while it is in collision, so it never runs down and resets the variable until the collision is no longer taking place. So, something like this:

GML:
// CREATE EVENT
can_hit = true;

// ALARM [0] EVENT
can_hit = true;

// COLLISION EVENT
if can_hit == true
{
can_hit = false;
// Add score values here or whatever
}
alarm[0] = 5;
Hope that helps
 
B

bebesnuggles

Guest
Personally, I use a combination of an alarm and a variable. You set the variable in the collision as well as the alarm, then in the alarm the variable is reset. The cool thing about this is that you make sure to set the alarm constantly while it is in collision, so it never runs down and resets the variable until the collision is no longer taking place. So, something like this:

GML:
// CREATE EVENT
can_hit = true;

// ALARM [0] EVENT
can_hit = true;

// COLLISION EVENT
if can_hit == true
{
can_hit = false;
// Add score values here or whatever
}
alarm[0] = 5;
Hope that helps
Thanks a ton!! This thought crossed my mind, but I wasn't sure!
 
Z

zendraw

Guest
just separate the code with an if statement

hit=0;
repeat ()
{
if (!hit)
{
hit=1;
run hit code
}
}
 
Top