every Interval
Run part of the program in a loop continuously at a time interval.
loops.everyInterval(500, function () {})
If you want to run some code continuously, but on a time interval, then use an every loop. You set the amount of time that the loop waits before the code inside runs again. This is similar to a forever loop, in that it runs continuously, except that there’s a time interval set to wait on before the loop runs the next time. This loop is useful when you want some of a program’s code run on a schedule.
Parameters
- interval: a number that is the amount of time in milliseconds to wait before running the loop again.
Example
At every 200 milliseconds of time, check if either the A or B button is pressed. If so, show on the screen which one is pressed.
loops.everyInterval(200, function () {
if (input.buttonIsPressed(Button.A)) {
basic.showString("A")
} else if (input.buttonIsPressed(Button.B)) {
basic.showString("B")
} else {
basic.clearScreen()
}
})