CurrentSpriteNum

From Director Online Wiki
Jump to: navigation, search

Prior to Director 6, the only way to know which sprite was currently executing a script was to use "the currentSpriteNum". Director 6 introduced behaviors; each behavior instance has access to "the spriteNum of me". Because of this, the official documentation suggests that the currentSpriteNum...

is not necessary when authoring with behaviors and is therefore less useful than in the past.

This is not entirely true.

The currentSpriteNum has an interesting and most useful property. It is updated continuously even when in authoring mode, when the movie is not playing. That is, you can place the currentSpriteNum property into a getPropertyDescriptionList handler, and use it to automate the preferences of the behavior you're attaching.

Example

 property chosenMember
 
 on getPropertyDescriptionList(me)
   vSpriteNum = '''the currentSpriteNum'''
 
   if vSpriteNum then
     -- The user has just dropped this behavior on a sprite, or is
     -- using the Behavior Parameters Dialog or the Property Inspector
    -- to modify the settings
     vSprite = sprite(vSpriteNum)
     vMember = vSprite.member -- use member of the current sprite
 
   else
     -- Director is simply recompiling this script
     vMember = member(1) -- use a dummy value
   end if
 
   vPropertyList = [:]
   vPropertyList[ \
 #chosenMember] = [ \
  #comment: "Choose a member", \
  #format:  #member, \
  #default: vMember]
 
   return vPropertyList
 end getPropertyDescriptionList