time
This content is for v0.2.1. Switch to the latest version for up-to-date documentation.
The time namespace provides timing primitives and thread sleeping.
Quick Reference
Section titled “Quick Reference”| Function | Signature | Return Type | Description |
|---|---|---|---|
time.sleep | time.sleep(ms) | void | Pauses execution for the specified milliseconds. |
time.ms | time.ms() | number | Returns monotonic system milliseconds counter. |
Detailed Methods
Section titled “Detailed Methods”time.sleep(ms)
Section titled “time.sleep(ms)”Suspends the running process or thread for ms milliseconds.
print("Starting countdown...");var i = 3;while (i > 0) { print(str(i) + "..."); time.sleep(1000); i = i - 1;}print("Liftoff!");time.ms()
Section titled “time.ms()”Returns the high-resolution monotonic time in milliseconds since system boot. Unaffected by system clock changes or daylight saving adjustments, making it ideal for games, animations, and benchmarking:
var start_ms = time.ms();
var i = 0;while (i < 500000) { i = i + 1; }
var duration = time.ms() - start_ms;print("Execution time: " + str(duration) + " ms");