CLASS v1.8.0

Timer

pykraken.Timer

A timer for tracking countdown durations with pause/resume functionality.

More about Timer

The Timer class provides a simple countdown timer that can be started, paused, and resumed. It's useful for implementing time-based game mechanics like cooldowns, temporary effects, or timed events.

Reference

PYTHON API
Timer(duration: float)

Create a new Timer instance with the specified duration.

Args

  • duration (float) — The countdown duration in seconds. Must be greater than 0.

Raises

  • RuntimeError — If duration is less than or equal to 0.

done

property
done: bool

bool: True if the timer has finished counting down, False otherwise.

A timer is considered done when the elapsed time since start (excluding paused time) equals or exceeds the specified duration.

duration

property
duration: float

Get or set the duration of the timer as a float greater than 0.

elapsed_time

property
elapsed_time: float

float: The time elapsed since the timer was started, in seconds.

Returns 0.0 if the timer hasn't been started. This includes time spent while paused, giving you the total wall-clock time since start().

progress

property
progress: float

float: The completion progress of the timer as a value between 0.0 and 1.0.

Returns 0.0 if the timer hasn't been started, and 1.0 when the timer is complete. Useful for progress bars and interpolated animations.

time_remaining: float

float: The remaining time in seconds before the timer completes.

Returns the full duration if the timer hasn't been started, or 0.0 if the timer has already finished.

pause

method
pause(self) -> None

Pause the timer countdown.

The timer will stop counting down but retain its current state. Use resume() to continue the countdown from where it was paused. Has no effect if the timer is not started or already paused.

reset

method
reset(self) -> None

Reset the timer to its initial state.

Stops the timer and resets it back to its initial, unstarted state. The timer can be started again with start() after being reset.

restart

method
restart(self) -> None

Restart the timer countdown.

This is a convenience method that combines reset() and start() into one call.

resume

method
resume(self) -> None

Resume a paused timer countdown.

Continues the countdown from where it was paused. Has no effect if the timer is not started or not currently paused.

start

method
start(self) -> None

Start or restart the timer countdown.

This begins the countdown from the full duration. If the timer was previously started, this will reset it back to the beginning.

Find your next step

Start typing to search the manual.