Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do you know the clone count?
- xCommander12
-
Scratcher
20 posts
How do you know the clone count?
In a recent clicker project I made, each time I click on the sprite, it creates a clone of it, and then ‘1’ gets added to the variable count… which works fine, but when I add erasers and other tools, I can't have it that way, I need a variable that depends on the clone count? Anyone know how to work it?
My current script
When this sprite clicked
Change Population by 1
Create clone of myself
Sorry, the block thing wasn't working
My current script
When this sprite clicked
Change Population by 1
Create clone of myself
Sorry, the block thing wasn't working
Last edited by xCommander12 (April 21, 2018 01:03:50)
- crisostimo
-
Scratcher
500+ posts
How do you know the clone count?
when green flag clicked
set [ID v] to [Original]
when this sprite clicked
create clone of [myself v]
when I start as a clone
set [ID v] to [Clone]
broadcast [Add To Clone Count v]
define Erase Me
broadcast [Substract From Clone Count v]
delete this clone
when I receive [Add To Clone Count v]
if <(ID) = [Original]> then
change [Clone Count v] by (1)
end
when I receive [Subtract From Clone Count v]
if <(ID) = [Original]> then
change [Clone Count v] by (-1)
end
- xCommander12
-
Scratcher
20 posts
How do you know the clone count?
But it still isn't working…
Check out my project and see if you can help me out further
https://scratch.mit.edu/projects/217203427/#editor
Check out my project and see if you can help me out further
https://scratch.mit.edu/projects/217203427/#editor
- asivi
-
Scratcher
1000+ posts
How do you know the clone count?
You start setting the var to 0, everytime you create a clone change(increase) by 1, and let clones to change(decrease) by -1 and then delete, just make sure that clone count is a variable for all sprites(global). That is all.
- deck26
-
Scratcher
1000+ posts
How do you know the clone count?
Maybe first have the project identify what a clone is. Make a private varable in all cloneing sprites named “clone.” In each of the sprites at the start of the code addSo that's another option. Either you keep track as you add or delete clones or you get Scratch to do a count when you need it. Personally I'd go for the former unless you have few clones and will only need the information once.set [clone v] to [0]
In the start of the “when I start as clone” script add aset [clone v] to [1]
Then create a variable named “clone count.”
In the stage make thiswhen green flag clicked
forever
set [clone count v] to [0]
broadcast [count clones v] and wait
end
And in all the cloning sprites make thiswhen I receive [count clones v]
if <(clone) = [1]> then
change [clone count v] by [1]
end
If followed correctly you should get an exact reading on clone count.
@xCommander12 - you forgot to make the ID a local variable so when a clone is created the sprite's ID is no longer ‘original’ and there is nothijng handling the count.
@Topflight24sub2yde - if the above doesn't help you should create your own topic and share your project.
- Discussion Forums
- » Help with Scripts
-
» How do you know the clone count?



