Discuss Scratch

-gaIaxy
Scratcher
21 posts

Cloning problems

Ok, so basically I have four variables. Those variables will be changing throughout the game (always to whole numbers).
The four variables align with four costumes in a sprite. At the beginning of the game, I have the sprite set to clone each costume the proper number of times for it to match the variable. I've also created seperate variables just for keeping track of the number of clones of each costume.
I run into my problem after the variables start changing. I'm unsure of how to get the clones to keep up with the variables without accidentally deleting all the clones or creating a small army. As far as I know, there's no way to command a single clone to delete while commanding another to duplicate, and to make the matter worse I have to differentiate the clones in each costume.
I would prefer not to share the game unless absolutely necessary, though I'd be happy to clarify if something was unclear.
Thank you in advance for any help.

мan cannoт dιѕcover new oceanѕ υnleѕѕ нe нaѕ тнe coυrage тo loѕe ѕιgнт oғ тнe ѕнore.
~andre gιde
asivi
Scratcher
1000+ posts

Cloning problems

So you want an identifier for each clone, create a variable as “for this sprite only” and set it at the moment a clone start

when I start as a clone
set [cloneID v] to []//set to whatever, a number perhaps

when I receive [delete clone v]
if <(cloneID) = []> then
delete this clone
end

Last edited by asivi (Aug. 8, 2017 17:00:36)

-gaIaxy
Scratcher
21 posts

Cloning problems

Ok, I think I get how that would help me keep track of the different costumes, but I'm still not sure how to keep them matched to their variables. Theoretically, if I assigned a clone ID of 1 to each clone with the first costume, then told it to “delete this clone” if the variable is greater than the clone number, wouldn't it delete all of the clones with that ID?
Also, wouldn't the variable change every time I assigned an ID to a new clone, thus resulting in only one clone being identifiable?

Last edited by -gaIaxy (Aug. 8, 2017 17:09:28)


мan cannoт dιѕcover new oceanѕ υnleѕѕ нe нaѕ тнe coυrage тo loѕe ѕιgнт oғ тнe ѕнore.
~andre gιde
asivi
Scratcher
1000+ posts

Cloning problems

Do not name equal all the clones for a same costume.

https://scratch.mit.edu/projects/137925288/#editor see Sprite2
footsocktoe
Scratcher
1000+ posts

Cloning problems

-gaIaxy wrote:

Also, wouldn't the variable change every time I assigned an ID to a new clone, thus resulting in only one clone being identifiable?

Like this… ID is a local variable, not global…

set [ID v] to [0]
repeat (3)
change [ID v] by (1)
create clone of [myself v]
end

This results in 3 clones, one with ID=1, one with ID=2, and one with ID=3. Remember ID is a LOCAL variable so it is different for each clone.


SHOOT THE SPACE MONSTERS! ….. A game everyone can play! Bright colors, bonky sounds!
THE 12 BALLS OF CRAZY AL ……. New scrolling adventure game!

Powered by DjangoBB