8
Script Controller 357
you use the Script controller variable toolset to
create variables to assign to any part icular node or
controller track. This way, if you decide to later on
rename your scene objects, the scr ipt controllers
usingtheseobjectsarepreservedbecausethe
variables maintain the link to the nodes.
Otherwise, if you assig n, for example, a node to
a variable manually in the dialog’s Expression
window, that link becomes broken as soon as you
rename that particular node.
Note: It is especially important to assign nodes and
tracks to variables with the corresponding buttons
when using XRef scenes a nd objec ts.
See also
MAXScript Reference (page 3–973)
Procedure
Ex ampl e: To keep a n object centered rela tiv e to
other objects in the scene dur ing an anima tion:
1.
Name the object that should remain centered
foo and assign a Script controller to its Position
track.
2. Enter
foo
in the Name field and click Create.
The new variable is automatically added to the
Va r i a b l e s l i s t .
3. With the variable hig h lighted, click Assign
Node.
The Track View Pick dialog opens, listing the
contents of your scene.
4. Expand the Objects hierarchy until you loc ate
foo.HighlightitandclickOK.
The foo node is assigned to your variable.
5. Enter the following s cript i n the Script
Controller dialog’s Expression w indow:
local pos =[0,0,0]
for o i n object s w her e o != foo do
pos += o.pos
pos / (objects.count - 1)
This scr ipt computes the average position of
all objects, except the current one (written as
foo here) by setting up a loca l, iterating over
all objects except foo, accumulating a total
position vector, and computing the average
in the last line, which is the final result of the
script.
Interfa ce
Assigning a Script controller automatically opens
aScriptControllerdialogwhereyoucanentera
script. You can open the dialog subsequently by
right-clicking the track on the Motion panel or in
the Track View hierarchy and choosing Properties,
or clicking the Properties button on the Track
View toolbar.
Tip: You can resize the dialog by dragg ing an edge
or a corner.
Create Variable group
Name—Lets you enter and edit the name of user
variables.
Cr e a te —Createsavariableandaddsittothe
Var i a b l e s l i s t .
Delete—Removes the highlighted var iable from
the Variables list. You can also delete a variable by
tying its name into the Name field and click Delete.
Rename—Renames the highlighted variable.