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:
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.
fn time_p = print currentTime
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.
If a runtime error occurs in a callback function while it is being executed, an error message is displayed and that callback function is permanently disabled.
The time callback is not called during rendering, even if multiple frames are rendered.
The registered function is executed in a special context and not in the context of the code that created it. This means that the function cannot contain references to local variables in outer code nestings surrounding the function definition since those variables are on an execution stack that does not exist at the time the function is called. An important exception to this is utility and rollout panel locals, such as local functions, rollout variables and nested rollouts. You can refer to them in change handler code inside rollout code as they are associated directly with their rollout or utility object.
Note that it is the function value that is being registered, not the function name or global variable. This means that redefining the same-named function after registering it does not change the callback. You either need to unregister, re-define the function and then register it again, or make the registered function an intermediary which calls another function,
fn time_cb = print currentTime
fn tcb = time_cb()
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.
Callback functions remain registered after loading a new file or performing a 3ds Max reset.
Change Handlers and Callbacks
Change Handlers and When Constructs
Viewport Redraw Callback Mechanism
General Event Callback Mechanism