setInterval()

Overview

Repeatedly calls a function at the specified interval. Repeats until the session ends or clearInterval() is called with the timer ID.

Added in version 2.1.5

Format

var timerId = setInterval(functionToCall, interval);

Value Description Type Required Notes
functionToCall The function that should be called when the interval expires. Function Required  
interval The number of milliseconds before the function is called. Integer Required Must be at least 100 ms.
timerId A number that can be used to clear the timer. Integer Return  

Example 1

Copy
/* Add a message to the log every 10 seconds
*/
setInterval(function() {
    Logger.debug("It has been 10 seconds again");
}, 10000);

Example 2

Copy
/* Play a frog sound three times with 15 seconds between each sound.
*/
var count = 3;
var id = setInterval(function() {
    Device.beepPlayFile('frog.mp3');
    count--;
    if(count <= 0) {
        clearInterval(id);
    }
}, 15000);