Hi Michelle,
I also use a scheme for addressing sprites by name instead of channel number. I wrote
an article on it for DOUG and you can
find it at:
http://www.director-online.com/accessArticle.cfm?id=843
Briefly, instead of using sendallsprite I drop a behavior on each sprite that I want
to reference by name which . There is
also a group entry for sending to multiple sprites, and sprites can belong to multiple
groups. Basically when each sprite is
born it registers itself in a data member and I can then reference that data member
for sprite numbers in my code. So my code
would look something like
sid(#ball).bounce(5)
where the function "sid" returns the sprite reference ie: sprite(1)
This also allows you to address properties of the sprite like loc with this structure:
sid(#ball).loc=point(100,100)
I did some testing when I was working with on this and when you are dealing with a lot
of sprites on stage you will notice an
improvement in response vs a sendallsprites system since you are specifically
targetting the sprites you want to communicate
with and not sending out a blanket call that has to hit all the sprites.
let me know what you think,
Rob
Michelle Elliott wrote:
> Hi all. This is my first post here, so please pardon me if I'm addressing an issue
>inappropriate for this forum...
>
> I have developed a way of addressing sprites without using their channel number.
>Instead, I use a sendAllSprites command,
> and have the receiving scripts filter out extraneous messages using an addressing
>scheme as follows.
>
> Each sprite has a script attached called "Sprite Msg Filter". This script has a
>property list dialogue in which the user,
> during authoring mode, assigns a Function, Group, Name, and Index to the sprite.
>For example, a custom slider that
> controls Music Volume might have Function="Slider", Group="Options", Name="Music
>Volume", Index=1. If the
> "Sprite Msg Filter" script verifies that the command is intended for its sprite, it
>passes the command to the sprite using
> sendSprite(me.spriteNum)
>
> Here is an example to set the above mentioned volume slider to the maximum value
>(please excuse any typos, there
> may be a character missing somewhere):
>
> -- "Sprite Msg Filter" receiving syntax
> -- myFunction, myGroup, etc. are set via a property dialogue during authoring mode
> -- note: this is a simplified version of the filtering logic
> on SpriteMsg(me, strFunction, strGroup, strName, nIndex, strMsg)
> if (strFunction=myFunction and strGroup=myGroup and strName=myName and
>nIndex=myIndex) then
> msg = "sendSprite(me.spriteNum, " & strMsg & ")"
> do msg
> end if
> end
>
> -- calling syntax
> -- note: the 0 in "msg" is simply to demonstrate that arguments can be part of the
>message conveyed
> msg = "Slider_SetToMaximum, 0"
> sendAllSprites(#SpriteMsg, "Slider", "Options", "Music Volume", 1, msg)
>
> Additional logic allows the specification of wildcard values, to address multiple
>sprites: the argument "any" will
> match any value for Function, Group or Name, and the argument 0 (zero) will match
>any value for Index.
> "Sprite Msg Filter" also contains logic to allow indices to be specified (via the
>property dialogue) for an
> entire group of sprites, such as assigning the 52 cards in a deck the indices 1 to
>52, as long as they are in
> consecutive sprite channels.
>
> Not all sprites have a "Sprite Msg Filter" attached -- just the ones that need to be
>addressed. Note that by
> externalizing the filter (not putting it in the functional script itself) I can even
>use this method with behaviors
> from the standard library. (My first iteration included the filtering in the
>functional behaviors -- very ugly!)
>
> I have experimented with this method a fair amount, and found that it doesn't impose
>any significant overhead.
> The reason I use this method is so that I don't have to hardcode in sprite indices
>-- I tend to move sprites
> around in the score a lot.
>
> Okay, having explained my own method, here is my question: Is anyone doing something
>different that
> achieves the same ends, i.e., "logical addressing" that embodies domain-related
>concepts rather than using the
> default addressing provided by the IDE? I think my method is pretty elegant, but it
>does have overhead, and
> the indirection entailed can make debugging a bit trickier.
>
> Thanks!
>
> --
>
> Michelle Elliott
> Director of Game Development
> WickedWare, LLC.
>
> [To remove yourself from this list, or to change to digest mode, go to
> http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
> email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
> Lingo-L is for learning and helping with programming Lingo. Thanks!]
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]