41 posts
Posted 20 October 2012 - 12:22 AM
if xr == "run" then
print("The process will start in 5 seconds")
sleep(5)
print("Pulsing White")
rs.setBundledOutput("back", colors.white)
sleep(3)
rs.setBundledOutput("back", 0)
end
So i was wondering how do i make this repeate
169 posts
Posted 20 October 2012 - 12:29 AM
xr = "run"
while xr == "run" do
print("The process will start in 5 seconds")
sleep(5)
print("Pulsing White")
rs.setBundledOutput("back", colors.white)
sleep(3)
rs.setBundledOutput("back", 0)
end
200 posts
Location
Scotland
Posted 20 October 2012 - 03:01 AM
or just…
while true do
print("The process will start in 5 seconds")
sleep(5)
print("Pulsing White")
rs.setBundledOutput("back", colors.white)
sleep(3)
rs.setBundledOutput("back", 0)
end
or do you mean just the pulsing part?
print("The process will start in 5 seconds")
sleep(5)
print("Pulsing White")
while true do
rs.setBundledOutput("back", colors.white)
sleep(3)
rs.setBundledOutput("back", 0)
end
Although that wouldn't pulse it would just stay on because there is no pause between on and off.
print("The process will start in 5 seconds")
sleep(5)
print("Pulsing White")
while true do
sleep(1.5)
rs.setBundledOutput("back", colors.white)
sleep(1.5)
rs.setBundledOutput("back", 0)
end
209 posts
Location
In your fridge.
Posted 20 October 2012 - 03:55 AM
I assume you don't want it running for infinity, if you have a if xr == "run" then check, a for loop works for a set period, like so:
if xr == "run" then
print("The process will start in 5 seconds")
sleep(5)
print("Pulsing White")
for i = 1, 5 do
rs.setBundledOutput("back", colors.white)
sleep(3)
rs.setBundledOutput("back", 0)
end
end
The "i" variable is local only to that code block, you can name it whatever you like, "i" is the most common. You can even have multiple for i = 1, x do code blocks in the same code. It also accepts variables, like if you wanted to request an amount of iterations. Like the one above. It works if x is global, and set to a number. My personal favorite loop.
2005 posts
Posted 20 October 2012 - 09:00 AM
Hmm…I don't really have a favorite loop. But I like repeat until a lot compared to how much other people seem to use it. If you want to let a loop run until you do something to terminate it, repeat until is usually a good choice. While is for when you want to be able to skip a loop entirely if you don't need it. for is when you want the loop to execute a definite number of times based on the program state when the loop starts.