Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Which code do I use to make my script loop forever?

Asked by 9 years ago

What's the code snippit I use to make my script loop forever? I'm making a button change colors... :P

3 answers

Log in to vote
1
Answered by
Vividex 162
9 years ago

Most common way is to use a while loop A while (statement) do look is the most common ways to make a loop that continues on forever and ever unless you can possible use a break to end the endless loop.

An example:

while true do
    --Code
end

Another way to use a while loop is with a boolean statement such as..

while 5 < 9 do
    --Code
end

That basically does the same thing, but it runs if 5 is less the 9, if you where to put while 5 > 9 do, that wouldn't run the loop since 5 is not greater than 9.

Another common loop is a for loop, which runs a command a certain number of times, an example:

for i = 1, 10 do
    print("Hello world!") --Put your code
end

Which would print in output "Hello world!" ten times, 1 being the first, and 10 being the end. Think of the comma as the word "to", so it prints "Hello world!" once, then again, and again and so on until it has been printed 10 times. (Same if you replaced it with your code)

Ad
Log in to vote
1
Answered by
Ekkoh 635 Moderation Voter
9 years ago

You'd use a while loop, although I'd discourage it for what you're doing.

while true do
    -- code
    -- make sure you have wait
end
Log in to vote
0
Answered by 9 years ago

Just use while true do.

Answer this question