Discuss Scratch
- Discussion Forums
- » Bugs and Glitches
- » Cloning using broadcast messages
- 15A1AH
-
Scratcher
5 posts
Cloning using broadcast messages
I've noticed with multiple projects when I create a clone by using a broadcast message it creates tons of extra clones. The more clones that are needed to be created, the more extras are created as well. Idk why and I can't seem to fix it with code. Here's an example for one of the games I'm making:
when I receive [ v]
if <(foo) = [poison cloud]> then
create clone of [ v]
end
- blubby4
-
Scratcher
100+ posts
Cloning using broadcast messages
Clones also receive broadcasts. You can exclude clone from receiving them like this:
when green flag clicked
set [is clone? v] to [false] // Make this a "local variable"
when I start as a clone
set [is clone? v] to [true]
when I receive [ v]
if <(is clone?) = [false]> then
if <(foo) = [poison cloud]> then
create clone of [ v]
end
end
- 15A1AH
-
Scratcher
5 posts
Cloning using broadcast messages
Good suggestion! I'm not sure if it'll work with multiple clones or different sprites. And I assume you would need to do this for the clones?
when I start as a clone
wait until <(health or whatever) = [0]>
set [is clone? v] to [false]
delete this clone
- medians
-
Scratcher
1000+ posts
Cloning using broadcast messages
Good suggestion! I'm not sure if it'll work with multiple clones or different sprites. And I assume you would need to do this for the clones??when I start as a clone
wait until <(health or whatever) = [0]>
set [is clone? v] to [false]
delete this clone
You're meant to make the variable sprite only, and you can just create multiple sprite only variables then.
Also, you don't have to put the set block, but the health or whatever thing would only work if you used a sprite only health variable for each clone, otherwise every clone would have the same health variable.
- Discussion Forums
- » Bugs and Glitches
-
» Cloning using broadcast messages