Discuss Scratch

doji344hi
Scratcher
1 post

Counting Clones

I have a project that needs to count the number of clones on screen. The problem is that when I spawn in or delete a clone, the variable counting the number of clones increases by 1*(2^the number of other clones on screen). So if there is 1 clone on screen, and I spawn in another one, it increases by 2. If there are 4 clones on screen and I spawn in another one, it increases by 16. The reverse is true when I delete a clone, so when all the bullets are off of the screen it still goes down to exactly 0. I'd like some help with this, please!
My code looks like this:
the code that calls for the clones:
when green flag clicked
forever
if <key [space v] pressed?> then
broadcast [message1 v]
end
end

and the code that makes the clones:
when I receive [message1 v]
create clone of [myself v]

the code for counting the clones:
when I start as a clone
change [bullet# v] by (1)
switch costume to [someotherstuffhere v]
change [bullet# v] by (-1)
delete this clone

link to the project
https://scratch.mit.edu/projects/651095238/
Thingied
Scratcher
1000+ posts

Counting Clones

The problem is that clones are cloning themselves.

Make a new variable called “isClone” that is set for this sprite only. This will make the variable separate from each clone. Then make these changes:

Last edited by Thingied (Feb. 26, 2022 18:40:40)

Jereb-co7
Scratcher
100+ posts

Counting Clones

doji344hi wrote:

I have a project that needs to count the number of clones on screen. The problem is that when I spawn in or delete a clone, the variable counting the number of clones increases by 1*(2^the number of other clones on screen). So if there is 1 clone on screen, and I spawn in another one, it increases by 2. If there are 4 clones on screen and I spawn in another one, it increases by 16. The reverse is true when I delete a clone, so when all the bullets are off of the screen it still goes down to exactly 0. I'd like some help with this, please!
My code looks like this:
the code that calls for the clones:
when green flag clicked
forever
if <key [space v] pressed?> then
broadcast [message1 v]
end
end

and the code that makes the clones:
when I receive [message1 v]
create clone of [myself v]

the code for counting the clones:
when I start as a clone
change [bullet# v] by (1)
switch costume to [someotherstuffhere v]
change [bullet# v] by (-1)
delete this clone

link to the project
https://scratch.mit.edu/projects/651095238/

I use an Addon that tells me how many clones are on screen and it looks like there are 4 clones on-screen but It's actually 285. The problem isn't the clone but the message block or the…
when I receive [Shoot bullet v]

Block so fix that and relax free of any problems

Hi, I'm Jeremiah; A kid who likes coding. I want to help people and become successful. I pretty please want you to join a team called “Shappire games” to make projects I also want 200 followers at the end of 2022.

you wrote:

when green flag clicked
set [ I help you ] to [you help me]
if <( I help you ) = [you help me]> then
say [get scratchin'] for (2) secs
end
My account: Jereb-co7




Sincerely,


Jeremiah. B

Powered by DjangoBB