Repeat section of code for X length of time

I’m looking for suggestions on having a section of script run for a section of time. I tried a repeat for 5 minutes but the repeat loop only ran for 10 seconds.


put now
repeat for 10 seconds
wait 1
end repeat
put now

Gave me:
2009-08-27 12:59:16 -0600
2009-08-27 12:59:26 -0600

repeat for 5 minutes left as an exercise to the reader.


I ran that code segment and had it run for 10 seconds. However when I try

repeat for 10 seconds
Play “Glass”
end repeat

it only runs for three seconds. Any ideas?

We don’t have a “repeat for a period of time” statement. The only reason that viztester’s code took 10 seconds to execute is because it executed a 1 second Wait 10 times. “Repeat for 10” is the same as “repeat 10 times” --the “seconds” was ignored. If you want to do something for a period of time, you could do something like this:

Put now plus 10 seconds into stopTime
repeat while now is less than stopTime
     //do something
end repeat

Don’t try this with your “play bell” code though – for some reason it only plays once at the end of the loop. But if you put something like “put now” in the loop, it will output the current time repeatedly until the time elapses.

Thanks Matt. Worked like a charm