Execute something once in update event

SnakeKiller

  • Posts: 29
I'm making a platformer game and I have this snake that follows the player. When the snake reaches a certain distance,I want him stop moving and bite the player. I have everything working fine, but when he bites, it spawns the head several times. I know it's doing that because it's in an update event. Is there a way I execute certain things only once? Such as the actor in the event?

Alexin

  • *
  • Posts: 3127
Use a Boolean attribute and an IF block to execute your logic only once.

Pseudocode:
Code: [Select]
...
if <executed = false>
executed = true
run logic once
end if
...
"Find the fun"
alexin@stencyl.com

SnakeKiller

  • Posts: 29
I understand what you mean, I probably should have shown you the whole code. This is how I've been doing this. In my update event I used if statements to detect the distance. When It reaches striking distance it strikes.

For example:
Code: [Select]
...
if (Xdistance < 34)
moving = true;
end if

else if (Xdistance < -34)
moving = true;
end if

else if (Xdistance > -33 && Xdistance  < 0)
moving = false;
end if

else if(Xdistance > -33 && Xdistance  < 0)
moving = false;
end if
...

The problem is that reaches striking distance it stops moving. That condition will always be false even when I switch it to true. I understand why it's looping I don't know how to setup the code better.



SnakeKiller

  • Posts: 29
I figured it out! I got the actor to create once. There were several mistakes in my code. I still have a few things to figure out that's different from my question, but I think I'm on the right track. Thanks for helping!