Timer Manager

The timer manager object provides library support for calling functions with a time offset i.e. waiting a period before calling a function. It is loaded in battle and the frontend.

It is rare for battle scripts to need to talk directly to the timer manager as the battle manager automatically creates a timer manager and provides a pass-through interface for the most-commonly-used timer manager functionality. See the Timer Manager section of the battle_manager documentation for more information.

Direct access to the timer manager might be more useful for frontend scripts, but they are rarer in themselves.

Loaded in Battle loaded in battle
Loaded in Frontend loaded in frontend
Back to top

Creation

timer_manager:new([number tick time], [battle_manager battle manager])

Creates a timer_manager object. It is unnecessary for battle scripts to call this as one is created automatically by the battle manager, and stored internally.

Parameters:

1

number

optional, default value=100

Model tick time in ms. Defaults to 100ms.

2

battle_manager

optional, default value=nil

Battle manager, if creating in battle.

Returns:

  1. timer_manager

defined in ../working_data/script/_lib/lib_timer_manager.lua, line 59

Back to top

Callbacks

timer_manager:callback(function callback to call, number delay in ms, [string callback name])

Instructs the timer manager to call a supplied function after a supplied delay. A string name for the callback may also be supplied with which the callback may be later cancelled using timer_manager:remove_callback (note that in battle it's much more common to use battle_manager:remove_process).

Parameters:

1

function

callback to call

2

number

delay in ms

3

string

optional, default value=nil

callback name

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_timer_manager.lua, line 146

timer_manager:repeat_callback(function callback to call, number delay in ms, [string callback name])

Instructs the timer manager to call a supplied function after a supplied delay, and then repeatedly after the same delay. A string name for the callback may also be supplied with which the callback may be later cancelled using timer_manager:remove_callback (note that in battle it's much more common to use battle_manager:remove_process).

Parameters:

1

function

callback to call

2

number

delay in ms

3

string

optional, default value=nil

callback name

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_timer_manager.lua, line 209

timer_manager:remove_callback(string name name to remove)

Instructs the timer manager to remove any active callback with the supplied name. This is the main method at the level of timer_manager to remove callbacks, however on the battle_manager it's more common to call battle_manager:remove_process instead (which also removes matching Watches).

Parameters:

1

string

name name to remove

Returns:

  1. boolean any callbacks removed

defined in ../working_data/script/_lib/lib_timer_manager.lua, line 220

Back to top

Legacy Timers

Do not use the functions provided here! Do not remove this either, however, as the callback system is built on top of it.

timer_manager:register_singleshot_timer(string function name, number time in ms)

Registers a handler name (function name) to be called and a period in ms after which to call it. Do not use this unless strictly necessary - it's only provided for legacy support. Use timer_manager:callback instead.

Parameters:

1

string

function name

2

number

time in ms

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_timer_manager.lua, line 303

timer_manager:register_repeating_timer(string function name, number time in ms)

Registers a handler name (function name) to be called and a period in ms after which to repeatedly call it. Do not use this unless strictly necessary - it's only provided for legacy support. Use timer_manager:repeat_callback instead.

Parameters:

1

string

function name

2

number

time in ms

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_timer_manager.lua, line 322

timer_manager:unregister_timer(string function name)

Cancels a timer registered with timer_manager:register_singleshot_timer or timer_manager:register_repeating_timer. As is the case with those functions, don't use this unless strictly necessary.

Parameters:

1

string

function name

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_timer_manager.lua, line 334

Back to top

Debug

timer_manager:print_timer_list()

Writes the current timer list to the console, for debugging purposes.

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_timer_manager.lua, line 372

timer_manager:print_callback_list()

Writes the current callback list to the console, for debugging purposes.

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_timer_manager.lua, line 398

timer_manager:clear_callback_list()

Clears all callbacks. This shouldn't really be used for client scripts, if you need to do this you're probably doing something wrong.

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_timer_manager.lua, line 431

Last updated 25/08/2021 12:07:50