8

State Transition Dialog 1061
Once you’ve executed this assi gnment, you can
obtainalistoftheatmosphericspropertiesby
entering this command in the MAXScript Listener:
ShowProperties atmos_fog
Also, the third line i n the sample script isn’t
necessary for the cognitive controller; it simply
prints the result of the test in the Listener w indow
for debugging purposes.
Testing Anoth er Delegate’s Be havior
You might want to determine in a transition script
which behavior is currently influencing a certain
delegate. Crowd provides a MAXScript-based
method for doing this. You can even check
whether a particular delegate is specified as a
target within that behavior. An example would be
acocktailpartysceneinwhichBettyavoidsHarry
if Harry is seeking Sally. But if Harry is avoiding
Sally, then B etty wi l l seek Harry.
Thefollowingexamplescriptistakenfromthe
sample file
party.max
,whichyoucanfindin
cstudio\tutorials\crowd_basics
directory in your
3ds Max path. The scene uses a more complex
scenario than the example described in the
previous par agraph. Following is an overvie w, but
to fully understand the setup, you should examine
the scene. Study, in part icular, the behavior
assignments and cognitive controllers, which use a
total of eight different transition scripts.
Six delegates are confined in a "room " defined by
four grids , using a Wall Repel behavior. Delegates
1, 2, 3, and 5 simply wander at random during the
simulation. However, delegate 4 uses a cognitive
cont roller (cc1) that tells it to start wandering,
and then switch to one of three Avoid behaviors
if members of one of three arbitrary pairs of
delegates come within 50 units of each other. Each
of the Avoid behaviors targets a different group
of three delegates, two of which include delegate
2. Delegate 6 is assigned a second cognitive
controller(cc2)thatusesthefollowingscriptto
tell it to switch to an Avoid behavior if delegate 4 is
avoiding delegate 2. The heart of the script is this
line in func tion
transfunc4
:
Note: See the online
User Reference
for this sample
code.
Load the file, press F11 to open the Listener
window, and then solve. The Listener window
displays a message whenever delegate 4 is found to
be avoiding delegate 2.
Youcanusethisscriptasisinyourownsimulations
to check for whether one delegate is avoiding a
second by substituting the delegates names in the
above line, and also substituting the names of your
Avoid behaviors in the list in
transfunc4
,addingor
deleting lines as necessary.
The example script i l lustrates a second important
point: Cognitive controller transition scripts can
cont ain multiple functions. Crowd first executes
the function specified in the State Transit ion
dialog > Transition Condition field, and that
function calls one or more additional functions in
the script, which, of course, can also call funct ions.
In this case,
transfunc4
calls the first function,
isDelegateAvoiding
, p assing it three p arameters.
Lastly, the script contains a special function,
getBehaviorType
, that compares an input behavior
against a list of known behaviors, and on a
match, returns the known behavior. In this case,
transfunc4
runs through the list of behaviors
currently influencing Delegate04, testing ea ch with
getBehaviorType
,andifanAvoidbehaviorisin
effect, proceeds to check whether Delegate02 is
an obstacle of that Avoid behavior. Use of this
function is more efficient and flexible than testing
forspecificbehaviors,especiallyifyourscene
contains many behaviors of the same t ype, or
you’re constantly editing behavior settings. You
can see the returned behav iors by removing the
comment (double hyphen) f rom the beg inning of
the following line in
transfunc4
.