MAXScript Language Reference > 3ds Max Objects > Animation Controllers > Controller Types > Script Controllers >

# Script Controller - Avoiding Circular Dependency

| Animation Controllers - Quick Navigation

Target and Object variables in Script Controllers will cause the whole object subAnim treeto be evaluated when the controller value is updated.

In the cases where the final result of the script controller has to depend on other properties of the same object it is assigned to, creating a Target or Object Variable will be prevented by MAXScript with a Runtime error to avoid such "vicious circle" conditions. Otherwise the update of the controller would have caused other properties to update and in turn cause the controller to be updated again, without end.

DOES NOT WORK:
    obj = Teapot ()
    $Teapot:Teapot01 @ [0.000000,0.000000,0.000000]
    obj.scale.controller = scale_script()
    Controller:Scale_Script
    obj.scale.controller.addTarget "pos" obj.position.controller
    -- Runtime error: Cannot add/set object, would create circular dependency: Controller:Position_XYZ
    obj.scale.controller.setExpression "[0.01*pos.x,1,1]"

In these circumstances, a Node Variable can be used instead.

The variable will contain a reference to the scene node and the script controller's expression will access the necessary property from the node instead of pointing directly at a subAnim or MAXWrapper object:

WORKS:
    obj = Teapot ()
    $Teapot:Teapot01 @ [0.000000,0.000000,0.000000]
    obj.scale.controller = scale_script()
    Controller:Scale_Script
    obj.scale.controller.addNode "obj" obj
    true
    obj.scale.controller.setExpression "[0.01*obj.pos.x,1,1]"
    true

Moving the teapot along the X axis will automatically scale its X axis according to the distance to the world origin.

#### See Also

- Script Controller - Avoiding Circular Dependency

- Referencing Nodes and Controllers in Script Controllers FAQ

- Script Controllers

- Using Script Controllers