Skip to main content
Participant
May 9, 2015
Question

Opposite of while?

  • May 9, 2015
  • 1 reply
  • 572 views

So, I was working with the collision detection in my game and something came up -

I had to change an if statement to an while statement. Simplified code follows:

if(colision)                                             while(colision)

{                                                            {

player.y -=5;                                             player.y -=5;

playerColided = true;                                 playerColided = true;

}                                        ------------>       }

else                                                       ???

{                                                            {

playerColided = false;                              playerColided = false;

}                                                            }

Once I changed to while, I could not find something to do the "else" role, like "while not" or something like that, in a manner that while the while statement is not active, the playerColided Boolean becomes false. Is there an statement that can do this?

Thanks in advance, Dan.

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
May 10, 2015

A 'while' is a looping process, whereby as long as the condition remains true it will continue to cycle thru that code... there is no 'else' option.  What you might try is to move that 'while' inside the if conditional you started with.  You probably don't want to do that though because a loop will process entirely in the blink of an eye whereas you probably want to be able to see the object moving.

You probably want to look into using an ENTER_FRAME event listener that executes an event handler with that conditional inside it.  The ENTER_FRAME event occurs at the frame rate of your file, which makes it very helpful for animating things as if they were in a timeline tween.