Click to go to the home page.

See Also
"Script Writer" Movie Script


Site Nav

css drop down menu by

Script Writer wfsWriteBehaviorCode Handler

wfsWriteBehaviorCode (theSpriteNum, theScriptName)

Click to go to top of section. Function

wfsWriteBehaviorCode is a tool to be used at authoring time to help you write code that dynamically attaches a behavior to a sprite.

wfsWriteBehaviorCode generates and returns code that, when tweaked and run, will attach the specified behavior to a specified sprite. You call wfsWriteBehaviorCode from the Director Message Window while the movie is running and theScriptName is attached to theSpriteNum, and theSpritenum is instantiated.

wfsWriteBehaviorCode looks at the way that theScriptName is configured as attached to theSpriteNum and returns a string that can call wfsAttachBehavior in such a way that the behavior would be so configured when attached to a sprite dynamically.

The wfsWriteBehaviorCode handler is in the "Script Writer" movie script, so you must have a copy of this script in a cast. You must also have a copy of the "1: prepareMovie" script and the "Dynamism" script.

Click to go to top of section. Parameters

theSpriteNum: is an integer that indicates the sprite that already has theScriptName attached to it.

theScriptName: is a string that indicates the name of the behavior you want to attach to a sprite.

Click to go to top of section. Return Value

wfsWriteBehaviorCode returns a string that contains a call to wfsAttachBehavior, normally. However, if theScriptName contains a getPropertyDescriptionList handler that contains string properties that contain quotation marks or the RETURN character or script object references, wfsWriteBehaviorCode will choke and raise an alert. In this case, you need to actually write the call to wfsAttachBehavior yourself rather than have wfsWriteBehaviorCode write the code for you. Sorry, it's a problem with the Director value() function.

Click to go to top of section. Examples


Suppose you want to attach some behavior called "my behavior" dynamically to a sprite at run-time. Suppose also that "my behavior" has a getPropertyDescriptionList handler that contains two properties: pMyProp1 and pMyProp2. Suppose that the default value for pMyProp1 is "default" and the default value of pMyProp2 is 8.

Suppose also that you have attached "my behavior" to sprite 5, and configured the Parameter Dialog Box for the behavior so that pMyProp1 is "some string" and the pMyProp2 value is 10, ie, different values from the default PDL values.

You start the movie and navigate to a point in the movie where sprite 5 is instantiated with the "my behavior" script attached to it as above.

In the Message Window, you type the following and then press the return key.

put wfsWriteBehaviorCode(5, "my behavior")

What you see in the Message Window is

theScript = wfsAttachBehavior("my behavior", theNewSpriteNum, 
		[#pMyProp1: "some string", #pMyProp2: 10])

This is supposed to be one line of Lingo code, by the way. You copy the above line and paste it into your code wherever you like. You change "theNewSpriteNum" to the integer indicating the sprite you actually want "my behavior" to be attached to during run-time.


Suppose we have the situation of example 1 except pMyProp1 is configured, on sprite 5, to be the default value, "default".

Then the call from the Message Window to

put wfsWriteBehaviorCode(5, "my behavior")

would produce the following output:

theScript = wfsAttachBehavior("my behavior", theNewSpriteNum, [#pMyProp2: 10])

Note that the above line contains no reference to pMyProp1. That is because when you call wfsAttachBehavior, the [ ] list of properties only needs to specify those that differ from the default value, ie, wfsAttachBehavior will set a getPropertyDescriptionList property to the default value unless it is specified in the property list to have some other value.


You can specify properties in that property list that aren't in the getPropertyDescriptionList handler. For instance, suppose "my behavior" is configured on sprite 5 as in example 2, and "my behavior" has pMyProp3 that is defined in the behavior but not in the getPropertyDescriptionList. Then you can manually add like so to the output:

theScript = wfsAttachBehavior("my 
          behavior", theNewSpriteNum, [#pMyProp2: 10, #pMyProp3: 66])


Suppose you want to generate code that will attach the "4: Window/Menu Element" behavior dynamically to a sprite at run-time.

So you attach the "4: Window/Menu Element" behavior to a sprite (say sprite 5), and, say, configure it so that the element is to be visible initially. Then you run the movie, navigate to where the sprite is instantiated and, in the Message Window, and type:

put wfsWriteBehaviorCode(5, "4: Window/Menu Element")

The output looks like this:

theScript=wfsAttachBehavior("4: Window/Menu Element", theNewSpritenum, \
[#pWFSManagerName: theManagerName, #pWFSManagerSpriteNum: theManagerSpriteNum])

This is supposed to be one line of Lingo, by the way. Now you

  1. copy this code and paste it into your code;
  2. replace "theNewSpriteNum" with the spritenum of the sprite you want to attach the "4: Window/Menu Element" behavior to;
  3. replace "theManagerName" with the name of the manager you want the sprite to be part of;
  4. replace "theManagerSpriteNum" with the spritenum of the manager named in step 3.

We see in the above example that the output of wfsWriteBehaviorCode sometimes needs tweaking, ie, you sometimes need to replace variable names with values (or set the variable names in code above the generated code). In general, if wfsWriteBehaviorCode produces an aOverride parameter list that contains

#pSomeProperty: variableName

rather than a particular value for the property, you need to replace it with whatever you want to set the property to.


Click to go to the home pageScript Writer wfsWriteBehaviorCode Handler