This content has been marked as final. Show 12 replies
p_sprite = sprite(1) --(or whatever)
Thanks for this I had something similar-ish based on Director's documentation - all the right words but in a different order.
When I try though, it still doesn't respond. (For the moment the added script is just a simple mouseDown alert for testing.) Is there something I'm asking it to do that isn't allowed? The script 'dynPieceScript' is just sitting in the cast.
Here's the code:
on createPiece me
-- iterate i that is method of naming sprites
-- set up ref point for new piece
-- make a copy of the play piece
-- name the member, set pMember to it's image,
-- find an available channel, assign it to a sprite in place
myChannelNum=_movie.lastChannel-i myNewSprite=channel(myChannelNum).makeScriptedSprite(member(pMember.name), origLoc)
end createPiece me
Everything else works the way I expect it to - the moveable is fine etc. Any ideas?
One other thing, there's a commented out attempt to name the newly created sprite but I get a No Access script error. Does that mean I can't name a sprite created like this?
Just one quick thing I noticed in your make scripted sprite call, you can just use pMember for the member item in it like so,
myNewSprite = channel(myChannelNum).makeScriptedSprite(pMember, origLoc)
Also I am not sure what your reference to "my" is in your scripts but should probably be removed from what I can see. This might also explain why you get an error when trying to set the sprite name. So for that line try this instead,
Not sure that is the exact output you want since I am not sure what your reference to "my" is.
Is your script dynPieceScript a behavior script or a parent script?
You can not name a scripted sprite. It is annoying, and I do not
understand why this basic thing was not implemented, but it wasn't. You
have access to every sprite property except name.
Thanks for those replies. Very helpful.
Thanks CenturyMan for the cleaning up observation, I'm always trying to make my scripting more efficient. This code is from a larger behaviour and one of the bits you don't see here is 'my=sprite(me.spriteNum)'. It's a shame about naming, that would have been really useful.
I think I've come to a dead end on this attempt. The reference to scriptInstanceList in the 8.5 Lingo Dictionary says 'It can be set only if the sprite already exists and has at least one instance of behaviour already attached to it'. So that goes against my scripted sprite, doesn't it? Unless that's just out of date. If anyone has any good ideas for this I'd grateful, otherwise it's back to making lots of unique cast members with scripts, which obviously for the sake of elegance and time I wanted to avoided.
I have had success with making a scripted sprite (using the
makeScriptedSprite() method), then adding a script to it using the
sprite's scriptInstanceList. In fact, my code specifically checks to
see if the scriptInstanceList.count=0 before adding the new one. It
will only apply the script if the sprite has no other scripts attached.
Thanks for responding Mike.
I'll twiddle a bit more before abandoning this. Was the code you used so much different from what I have?
Nope. It was quite similar. Apart from the fact that I was checking to
see if the sprite's scriptInstanceList was empty before adding it, and
the script I gave it was an instance of a parent script. But your code
looks like it should work (apart from the sprite naming thing of course)
Your code should work since I took what you gave us and modified it slightly to make it work. I took the createPiece function and just stuck it in a movie clip and then just put a button on the screen that would call that function. Then after setting your my referenced variables to static ones since I was not sure on the values it seemed to work fine. The sprite naming still does not seem to be working but I don't get an error when trying to name it. I will attach the code I made,
Well that's pretty comprehensive, thank you.
I got yours working but couldn't integrate it into mine. Perhaps there's a difference in the scripts we're accessing? Yours was sitting in a movie script and mine in a cast member behaviour. Is there some sort of difference here about parents and behaviours?
Anyway, I'll keep on twiddling with this. You've been a big help, so I'll leave you alone now.
Is there a reason you have the script on a cast member instead of in a movie clip?
Now that's an interesting question. I'm used to making scripts either by writing them by going thro' a sprite (right click, script, kind of thing) or in the script window (which obviously puts that into the cast and then I apply it to a sprite or whatever). I usually only have one movie script. But then I was reading Tab Julius' book Lingo only last night and it was talking about having multiple movie scripts. I thought I was being tidy but between his comments and your question I'm starting to see that I've got a new step to make and work out what this can do for me.
To answer your question I think we might be talking at slightly cross-purposes. I meant that the dynPieceScript was a cast member. The createPiece script (and its other components) was attached to a sprite.
I can work how to achieve pretty much anything these days. But I'm working on making the way I achieve them more efficient and elegant script-wise.