Time Change Callback Mechanism

You can register one or more functions to be called whenever the current 3ds Max animation time is changed, such as when the user drags the time slider or plays the animation. The following methods let you register and unregister these callbacks:

registerTimeCallback <fn>
unRegisterTimeCallback <fn> | undefined )

You can register as many functions as you like. Each one is individually called whenever the time changes. The functions you register must take no arguments. They can access the updated current time through the MAXScript system variable currentTime .

EXAMPLE:

fn time_p = print currentTime
registerTimeCallback time_p

In the above example, the registered function causes the current time to be printed in the Listener window whenever the user moves the time slider or plays the animation.

You can also enable or disable time change callbacks globally.

<boolean> timeCallbacksEnabled()

Returns whether time change callbacks are enabled. Available in 3ds Max 2021.1 Update and higher.

<boolean> enableTimeCallbacks()
<boolean> disableTimeCallbacks()

Enables or disables time change callbacks. These functions return the current time change callbacks enabled state. So, for example, calling disableTimeCallbacks() when callbacks are already disabled will return false. Available in 3ds Max 2021.1 Update and higher.

showregisteredTimeCallbacks [to:stream] [asArray:<boolean>]

Returns a list of registered time change callbacks, listing the function name, source file (if applicable) and line number in the source file where the function is defined. If the optional to argument is specified, the output is sent to that output stream. If the optional asArray argument is specified, the return value is formatted as an array of arrays, where for each registered callback function the first element is the callback function name, the second element is the source file name and line number where the callback function is defined (or an empty string if the function was not defined in a file), and the third element is the actual function value which can be used to de-register the callback.

Special Considerations

EXAMPLE:

fn time_cb = print currentTime
fn tcb = time_cb()
registerTimeCallback tcb

In this case, the registered callback function, tcb , calls the real call back, time_cb , (by referencing the global variable it is defined in), meaning you can redefine time_cb() as often as you need and the callback will always invoke the latest definition. This is a useful technique to employ while you are developing and debugging a callback.