← Back to Docs

wait(ms)

wait(ms) pauses execution for the given number of milliseconds.

Syntax

wait(milliseconds);

Examples

wait(1000);    // pause 1 second
wait(500);     // pause 0.5 seconds
wait(3000);    // pause 3 seconds

Use with loops

wait() is commonly used inside while loops to satisfy the loop protection (2-second minimum per iteration):

class App {
    let i = 3;
    while (i > 0) {
        print("tick:", i);
        i = i - 1;
        wait(2100);    // keeps iteration above 2s
    }
}

Rules

  • Argument must be an integer (milliseconds)
  • Negative values throw a runtime error
  • wait(0) is valid but does nothing

Errors

wait("hello");  // [VDX] wait() expects an integer (milliseconds)
wait(-100);     // [VDX] wait() duration cannot be negative