Timer

Millisecond stopwatch helper for script timing checks and guarded waits.

Syntax

Timer(auto_start=True)

Constructor parameters

NameDescription
auto_startBoolean
Start counting immediately after creation.
Optional · Positional or named
Default: True

Returns

Example

timer = Timer(auto_start=False)
timer.start()
while not timer.is_elapsed(2000):
    wait(50)
timer.stop()

Fields

NameDescription
auto_startBoolean
Whether the timer starts immediately after creation. Assign True to start; assign False to pause.
Default: True
Constructor example
timer = Timer()
if timer.is_elapsed(500):
    text("half-second passed")

Methods

10 methods

Timer.start

Start counting if the timer is currently stopped.

Syntax

timer.start()

Returns

Timer — Returns the same timer for chaining.

Example

# Measure time in the calling flow
timer = Timer(auto_start=False)
timer.start()
wait(100)
print(timer.elapsed_ms())

Timer.pause

Pause counting while preserving elapsed milliseconds.

Syntax

timer.pause()

Returns

Timer — Returns the same timer for chaining.

Example

# Measure time in the calling flow
timer = Timer()
wait(100)
timer.pause()
print(timer.elapsed_ms())

Timer.resume

Resume counting from paused state.

Syntax

timer.resume()

Returns

Timer — Returns the same timer for chaining.

Example

# Measure time in the calling flow
timer = Timer()
timer.pause()
timer.resume()
wait(100)
print(timer.elapsed_ms())

Timer.stop

Stop counting and keep elapsed milliseconds frozen.

Syntax

timer.stop()

Returns

Timer — Returns the same timer for chaining.

Example

# Measure time in the calling flow
timer = Timer()
wait(100)
timer.stop()
print(timer.elapsed_ms())

Timer.reset

Reset elapsed time to 0 while keeping the current running state.

Syntax

timer.reset()

Returns

Timer — Returns the same timer for chaining.

Example

# Measure time in the calling flow
timer = Timer()
wait(100)
timer.reset()
print(timer.elapsed_ms())

Timer.restart

Reset elapsed time to 0 and start counting immediately.

Syntax

timer.restart()

Returns

Timer — Returns the same timer for chaining.

Example

# Measure time in the calling flow
timer = Timer(auto_start=False)
timer.restart()
wait(100)
print(timer.elapsed_ms())

Timer.elapsed_ms

Read total elapsed milliseconds.

Syntax

timer.elapsed_ms()

Returns

Number — Elapsed milliseconds.

Example

# Measure time in the calling flow
timer = Timer()
wait(100)
print(timer.elapsed_ms())

Timer.is_elapsed

Check whether elapsed time is greater than or equal to the provided milliseconds.

Syntax

timer.is_elapsed(time)

Parameters

NameDescription
timeNumber
Target milliseconds threshold.
Required · Positional or named
No default

Returns

Boolean — true when elapsed time reached or exceeded the threshold.

Example

# Measure time in the calling flow
timer = Timer()
wait(500)
if timer.is_elapsed(500):
    print("Elapsed")

Timer.is_running

Check whether the timer is currently counting.

Syntax

timer.is_running()

Returns

Boolean — true when timer is counting.

Example

# Measure time in the calling flow
timer = Timer()
print(timer.is_running())

Timer.is_paused

Check whether the timer is paused after being started.

Syntax

timer.is_paused()

Returns

Boolean — true when timer is paused.

Example

# Measure time in the calling flow
timer = Timer()
timer.pause()
print(timer.is_paused())