How, Random "wait for" in Typescript in CoSpaces?

Something like this but in Typescript:

1 Like

I came up with a solution. Not sure it’s the best but it works.

Does something every 1 to 3 seconds:

let nextCycle = 0;
let secondsCounter = 0

Time.scheduleRepeating(() => {
    nextCycle = randomNum(1, 3);            // Returns 1, 2 or 3
    secondsCounter++;                       // increment counter
    if(secondsCounter > nextCycle){
        secondsCounter = 0;                 // Reset counter
        Debug.log("Seconds: " + nextCycle); // Do something
    }
}, 1);                                      // Run once a second

1 Like