Discuss Scratch

amoorestl
Scratcher
18 posts

Accessing a specific clone

I was reading through a post here (http://scratch.mit.edu/discuss/topic/52550/?page=1#post-442218) and it brought up a question for me that I hadn't even considered asking. I posted a comment there with the question but it kind of got burried in the other comments so I thought I'd repost it here. In the comments on that post one user mentioned that you could access specifics of a certain clone of a sprite by id. I've set up a 9x9 game board of 81 clones of the same square. Problem is that, at times during the game, certain of those clones will need to change costumes. I thought I was going to have to re-clone the board each time that happened but I was enjoyed when I heard about IDs for the Clones. However, I don't know how to use them.

How would I program something like:
switchcostumeto1 of Sprite 1 Clone 1

And, how are the clone id's numbered? Starting with zero or one? Is the original sprite also numbered in that sequence?

Thanks.
drmcw
Scratcher
1000+ posts

Accessing a specific clone

You can number clones how you like. Just create a global variable and initilaise it to where you want the id to start.
Ensure the cloned sprite has a local variable (That's the important bit it must be local = for this sprite only) called id say. Then just use
whenIstartasaclonesetidtoclonecountchangeclone countby1. . .the rest of the script
It just relies on the fact that local variables are inherited by clones but are also unique to each clone.

You don't necessarily need id's for what you want.
whenthisspriteclickedswitchcostumetoclicked
would work with no id's, depends what you are trying to do?
amoorestl
Scratcher
18 posts

Accessing a specific clone

So, from there, could I just do a broadcast and then, within the scripts have something like this:

whenIreceiveChangeColorsifid=2 thenswitchcostumeto3
And, in so doing (with the variable being local) it would check the variable in each of the clones and just change the ones that are correct?

Just wanted to be sure I know what I'm doing (I'll be changing them quite a bit throughout the game so a single event trigger won't be effective as it will be different ones of the 81 changing each time).

Thanks.
Allen.
vidarfw02
Scratcher
100+ posts

Accessing a specific clone

This project will show you how to number your clones…and make them appear different depending on ID:
http://scratch.mit.edu/projects/24422627/


This project will show you how to keep track of a clones attributes like for example position:
http://scratch.mit.edu/projects/23916401/

For the last project press 1 three times to get some clones then try to click on a clone…but understand the first project first.
If you have any questions dont hesitate to ask


And to your last question above: Yes
You could easily use my first clone example project to test this. Make a block in sprite1 which broadcasts a message…and then in the “clones” sprite make a when I receive block and check ID and they make it say something or change costume…

Last edited by vidarfw02 (Sept. 22, 2014 13:04:58)

Powered by DjangoBB