What is a while loop and how do I make it?

From OHRRPGCE-Wiki
Jump to navigation Jump to search

A while loop is a section of code that repeats as long as a certain condition holds true. Sort of like telling the computer "do this, and keep doing it until this happens."

In a plotscript, a while loop looks like this:

while (condition) do, begin
 # various things you want the script to repeat
end
# various things you want to happen after the script finishes

condition is whatever you want to use as the condition for the while loop. If you use "x>>4", for instance, then the loop will keep running over and over again as long as x is greater than 4. If x drops to 4 or less, then when the loop finishes its current run-through, it'll move on to whatever's after the loop.

What GAME actually does is evaluate the condition, check to see if it's true, and if so, execute the contents of the loop, much like an "if" block. Then it checks the condition again, and so on, until the condition turns out to be false, at which point instead of executing the contents it skips ahead.

A loop that uses "true" as its condition will keep on going forever, so you'd better make sure there's nothing after it. This type of loop is useful in certain situations, such as if you're trying to implement your own control system or menu. Make sure you put a wait command into a loop like this or the game will not respond to you.

See Also[edit]