| script command: Loop |
What this does
| This command allows you to run a set of commands over and over. It will continue to run them as long as the variable condition in this command is true. It's sort of like a condition command except that it'll repeat over and over. When the loop command is running, the game will repeatly run the commands inside of it. When the loop command stops running, the game will run the script commands that come AFTER it. | To make the darn thing stop, you need to change the value of the variable it's looking at so that it's no longer equal to the value this command is looking for. For example, if you tell it to repeat as long as a variable named myVar equals 7, it'll run until you change the contents of myVar to something else.
Tricks
Making an infinite loop. If you actually WANT the loop to run forever (as long as the player is on the map) then type the word undefined into BOTH the variable and value boxes. This works because there's normally no variable by the name of "undefined", so its value will be undefined. If that's what you tell the loop command to look for, then it'll run as long as that variable doesn't exist. This is how loop commands are set when you first create them. Looping a few times. To do this, you need to first create a variable and put a number into it. Then, you create the loop command and tell it to run as long as that variable's value is > 0. Finally, you need to put a variable command INSIDE the loop's script that decreases the variable's value by 1. What will happen is that the variable will repeatedly count down until it reaches 0. Then the loop will stop. | Moving movieClips. This is an advanced trick, but you can use a loop command to make a movieClip move until it reaches a certain location. To do this, you would type in the movieClip's _x or _y property into the variable box like so: OVERLAY.myClip._x Then you would type in the destination coordinate into the value box, and have the loop run until it passes that location. Finally, within the loop, you need to create a variable command that increases or decreases that movieClip's _x position. The loop will run until the movieClip passes the desired location. I say "passes" because, unless you're moving the movieClip by only 1 pixel each time, it'll skip ahead a few pixels each time the loop runs and may very well skip over the exact location you specify. If you want the movieClip to stop at a specific location, then put another variable command AFTER the loop and have it set the movieClip's location to an exact value.
| Last updated: December 27, 2014 |