MAXScript Language Reference > Names, Literal Constants, and Expressions > Context Expressions >

# Nested Contexts

All context expressions remember the prior setting of the context when they are set, and restore the original setting when the expression completes. Therefore, you can nest context clauses in any way you want, including contexts of the same type to override an outer setting.

EXAMPLE:
    with animate on, at time t
    (
    move ... -- all these place keys
    rotate ...
    animate off -- turn off animate for a bit
    (
    move ... -- working maneuvers, these don't effect animation
    rotate ...
    ) -- animate on is restored here
    scale ... -- place keys again
    ...
    )

Further, all the contexts are dynamically scoped. Any code inside a context expression, any functions that code calls, and functions they call down to any level, are executed in the current prevailing context. So, a function can move an object and place keyframes at a certain time when called from one client and do no keyframing when called from another client, depending on how the callers have set up the contexts. Of course, the called function can explicitly set its own contexts if it wants to, overriding those that may have been set up by the caller.