|
behaviorFinder
At 10:52 14.12.98 +0000, James wrote:
>Hi
>
>anyone know a good way of getting all the sprites numbers of the sprites
>with a certain behavior attached to them to be in a list that is a property
>in one of the behaviors. ONLY using behaviors, no frame script,
>
James,
below are snippets from a working behavior which do just that: collect a list of sprites which have this behavior attached. Actually it is a bit more specific since the value of a identifier is checked thus to allow several independent groups of sprites with this behavior to coexist.
------------------------------------------------------------------------
property myInited -- Flag
property myLOurSprites -- List of Sprites belonging to the Group
property myMagicSpell -- symbol to identify members of a sprite group
property mySprite
on beginSprite me
set myLOurSprites = []
set myInited = FALSE
set mySprite = the spritenum of me
if voidP (myMagicSpell) then set myMagicSpell = #someDefault
end
on enterframe me
-- Init not done?
-- Could be in beginSprite but saves trouble with rect of sprite
-- when done later. Only executed once by the first sprite of the
-- group with this behavior
if not (myInited) then
sendallSprites (#initialize,myLOurSprites,myMagicSpell)
tellGroupOurSprites me
end if
end
on initialize me,dL,dSpell
if myMagicSpell <> dSpell then return
set myInited = TRUE
append dL,mySprite
end
on setLOurSprites me,dL
set myLOursprites = dL
end
on tellGroupOurSprites
repeat with dSprite in myLOurSprites
if dSprite = mySprite then next repeat
sendSprite dsprite,#setLOurSprites,myLOurSprites
end repeat
end
-------------------------------------------------------
|