Director FAQ || Notes ~ Short Index ~ Full Index ~ Search || Prev ~ Next ||

[11] Puppets


Director FAQ [11] Puppets

[11.1] What are puppet sprites for?

A sprite's puppet property defines whether it is controlled by the score or by lingo. If the puppet of a sprite is true, it will behave as instructed by your scripts. If false, the sprite will behave according to the directions in the score.

The default puppet state is false. This means that initially, all sprites act under the control of the score. When you issue a

  puppetSprite channelNum, true
command, the specified sprite's behaviour is detached from the score and you can manipulate it via lingo. Conversely, a
  puppetSprite channelNum, false
command releases the sprite from script control and returns it to the score.

So, whenever you want to control sprites via lingo, you need to make them puppets, and this tends to be necessary for anything but the most rudimentary interactivity.

[top]


Director FAQ [11] Puppets

[11.2] When should I set puppets on and off?

The basic rule is, set the puppet of a sprite to true just before you want to start controlling it with lingo, and set it to false immediately before you want to revert to score control. However, there are some things about this that need clarifying.

First of all, score control includes all those places where you jump to some other frame and want the stage to look the way you set it up in that frame. If you do this with some of your sprites set as puppets, they generally won't change in the way you want, but will stay as your scripts have left them. In general, therefore, you should unpuppet things before any major "go to" commands.

Secondly, the score only asserts its control if there's something for it to do, such as a transition or a loop. If there's a sprite onstage which doesn't move or change in the score, your lingo scripts may be able to move it around and manipulate it for a while even though it isn't a puppet. In general this isn't a good idea, since as soon as the score finds something to do with the sprite all your changes will be lost.

Thirdly, puppetness is a property of a channel, rather than a sprite, so lingo will quite happily let you puppet a channel that doesn't have anything in it. This is almost invariably a bad thing to do and leads to unpredictable and frequently ugly behaviour. Always make sure there's something in a channel before puppeting it.

[top]


Director FAQ [11] Puppets

[11.3] Why do my puppets keep reverting to the score or behaving strangely?

Most likely this is because they aren't being made puppets at the right time, or over the right set of frames. A sprite being manipulated in lingo needs to be a puppet for as long as the changes are intended to persist. Only unpuppet puppetSprites when you want them to return to their score positions.

As mentioned above, another thing which can make puppets behave strangely is if they were declared puppets with nothing in the channel.

[top]


Director FAQ [11] Puppets

[11.4] Can I do transitions and stuff without using the score?

Palettes, transitions, sounds and tempo can all be modified using lingo, though there are some restrictions.

The puppetPalette command can be used to change the current palette and to create transitions between the current palette and the one being changed to:

  puppetPalette "myPalette", 20 -- 20 represents the rate if transition
Like puppetSprite channels, puppetPalettes persist until reset with a
  puppetPalette 0
command, and the contents of the palette channel will be ignored until such a command is issued.

Other palette channel effects, like Fade To Black, cannot be directly performed from Lingo.

Transitions can be generated with the puppetTransition command:

  puppetTransition 37, 0, 8, false
-- see the Lingo Dictionary for a full list of the parameters for this!

The transition will occur on the next frame entry. This includes re-entering the current frame. If you are paused on the frame, you could force the transition to occur by adding

  go the frame
after your puppetTransition command. Puppet transitions do not persist, but take place only once.

The sound channel can be puppeted using the puppetSound command, for which the official syntax is:

  puppetSound mySoundCast
In this case, only sound channel 1 is affected. PuppetSound both specifies a sound to be played and makes the first sound channel a puppet. The channel remains under lingo control until a
  puppetSound 0
command is issued. Until then, score instructions in sound channel 1 will be ignored and sounds will only be played by issuing further puppetSound commands.

However, an undocumented feature is the use of puppetSound with multiple sound channels:

  puppetSound channelNumber, cast mySoundCast
With Macromedia's MacroMix DLL providing the mixing ability of Apple's Sound Manager 3 under Windows, this seems to work seamlessly cross-platform as of version 4.0.4, but as usual the caveats of section 1.8 need be borne in mind.

The volume of individual sound channels can be varied independently by using the volume of sound property:

  set the volume of sound channelNumber = 255
Sound volume is officially restricted to the range 0-255, but on the Mac at least it may be overdriven to higher levels if desired.

Finally, the tempo can be changed using the puppetTempo command:

  puppetTempo 30
This will adjust the frame rate of the Director movie. The new tempo stays in effect until altered either by another puppetTempo command or by a change in the tempo channel.

Other tempo channel effects (waiting for a specific time or for a particular event) must be scripted explicitly. This is commonly done by looping on the frame until the required event takes place, eg to wait for a mouseClick:

-- you probably shouldn't do this this way with a slow frameRate... 
  on exitFrame
    if not the mouseDown then go the frame
  end exitFrame
[top]


Director FAQ [11] Puppets

[11.5] Can I puppet a channel that has nothing in it?

Although this has frequently been cited as a cause of trouble, it is demonstrably possible to puppet an empty channel and fill it with a sprite on the fly. How desirable or advisable it is to do this remains to be seen, but in essence all that is required is that you supply as many of the properties the sprite would normally acquire from the score as possible. The type of sprite property seems especially important in this respect. Eg:
-- puppetizing a sprite with nothing in the score

on insertNonPuppet stageSprite, cstNum, where
  -- first puppet the channel
  puppetsprite stagesprite,true

  -- set its properties
  set the castNum of sprite stageSprite = cstNum
  set the type of sprite stageSprite = 16
  set the ink of sprite stageSprite = 0
  set the foreColor of sprite stageSprite = 255 
  set the backColor of sprite stageSprite = 0

  -- in this case we'll just place our new cast 
  -- and keep it at it's natural size, but in theory 
  -- we may want to adjust its rect
  set the loc of sprite stageSprite = where 
  set the stretch of sprite stageSprite = false

  -- update it
  updatestage
end insertNonPuppet
[Thanks to Paul Farry <p.farry@cqu.edu.au> for demonstrating this technique.]

[top]


Director Web: Director FAQ [11]: Puppets

aricopa Center for Learning and Instruction (MCLI)
Maricopa County Community College District

HTML by Zac Belado, zac@wimsey.com

The Internet Connection at MCLI is Alan Levine --}
Comments to levine@maricopa.edu

URL: http://www.mcli.dist.maricopa.edu/director/faq/faq11.html