Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to create just a single clone
- DamoDog
-
38 posts
How to create just a single clone
I am making a game where an object spawns every ‘x’ amount of seconds, and there will usually be many clones on the screen (maybe 10 or so), but the problem is, every time it clones itself, it clones EVERY single ‘clone’ out there, so it will clone 1, then it will clone both of them (4) then it will become (8) and so on. Does anyone know how to prevent this and only clone the original sprite?
Thanks for any help!
Thanks for any help!
- DamoDog
-
38 posts
How to create just a single clone
Don't worry I got it, it turns out when you write ‘create clone of ’myself'' it clones all clones of that sprite but when you write ‘create clone of ’Sprite 1'' then it only clones the original sprite
Thanks!
Thanks!
- stickfiregames
-
1000+ posts
How to create just a single clone
I can't know without seeing your project, but is the create clone block being triggered by a broadcast? Clones can receive broadcasts, so that means any clone receiving the broadcast would also clone itself.
- TheLogFather
-
1000+ posts
How to create just a single clone
No, that's not correct. Don't worry I got it, it turns out when you write ‘create clone of ’myself'' it clones all clones of that sprite but when you write ‘create clone of ’Sprite 1'' then it only clones the original sprite
Probably what's happening is as stickfiregames says above – you are creating the clones from a broadcast receiver script, and all clones receive the broadcast and run that script, thus all creating clones.
When you switch to “create clone of sprite” (rather than “myself”) all the clones are still creating clones of the original sprite. What's different is likely that you don't notice, because they all get created on top of each other and all do the same thing.
If you only want one clone to be created from the broadcast, then what you need to do is to ensure that only one object (i.e. one clone, or the original sprite) creates a clone – and all others ignore the script.
You can do this by using an “if” test of some form. For example, if all the clones are set to a costume that's different from the one in use by the original sprite, then you can use that costume as a test (i.e. have the script only create the clone if the current costume is the one the original sprite has). Or maybe use a “this sprite only” variable (e.g. call it “iamaclone”) that gets set to zero in the green-flag script, and set to one in the “when I start as a clone” script – so you can use that to ensure only the original sprite does the “create clone” script.
Last edited by TheLogFather (June 1, 2017 12:58:52)
- DamoDog
-
38 posts
How to create just a single clone
https://scratch.mit.edu/projects/164134392/
The new problem I am having is that whenever the sprite reaches the base, it should only do 1 single damage, instead, it is doing 1 damage from every single sprite cloned! Even though I am deleting the clones when they get hit, they are still doing damage? Help?
Thanks!
The new problem I am having is that whenever the sprite reaches the base, it should only do 1 single damage, instead, it is doing 1 damage from every single sprite cloned! Even though I am deleting the clones when they get hit, they are still doing damage? Help?
Thanks!
- TheLogFather
-
1000+ posts
How to create just a single clone
https://scratch.mit.edu/projects/164134392/Same problem as above (that you still haven't solved) – you have *loads* of clones (created by other clones, as well as the original sprite) all receiving a broadcast, and every one of them reduces the value by one…
The new problem I am having is that whenever the sprite reaches the base, it should only do 1 single damage, instead, it is doing 1 damage from every single sprite cloned! Even though I am deleting the clones when they get hit, they are still doing damage? Help?
Thanks!
Last edited by TheLogFather (June 1, 2017 13:03:22)
- DamoDog
-
38 posts
How to create just a single clone
No, that's not correct. Don't worry I got it, it turns out when you write ‘create clone of ’myself'' it clones all clones of that sprite but when you write ‘create clone of ’Sprite 1'' then it only clones the original sprite
Probably what's happening is as stickfiregames says above – you are creating the clones from a broadcast receiver script, and all clones receive the broadcast and run that script, thus all creating clones.
When you switch to “create clone of sprite” (rather than “myself”) all the clones are still creating clones of the original sprite. What's different is likely that you don't notice, because they all get created on top of each other and all do the same thing.
If you only want one clone to be created from the broadcast, then what you need to do is to ensure that only one object (i.e. one clone, or the original sprite) creates a clone – and all others ignore the script.
You can do this by using an “if” test of some form. For example, if all the clones are set to a costume that's different from the one in use by the original sprite, then you can use that costume as a test (i.e. have the script only create the clone if the current costume is the one the original sprite has). Or maybe use a “this sprite only” variable (e.g. call it “iamaclone”) that gets set to zero in the green-flag script, and set to one in the “when I start as a clone” script – so you can use that to ensure only the original sprite does the “create clone” script.
Im not sure how to put that in a script, could you please do an example script for me? Thanks!
- TheLogFather
-
1000+ posts
How to create just a single clone
Im not sure how to put that in a script, could you please do an example script for me? Thanks!
Last edited by TheLogFather (June 1, 2017 13:15:43)
- DamoDog
-
38 posts
How to create just a single clone
Im not sure how to put that in a script, could you please do an example script for me? Thanks!
I actually still don't get it, I will try it and let you know if it works, Thanks!
- DamoDog
-
38 posts
How to create just a single clone
Have you looked at the project? If you haven't, I would suggest looking at it so you can see the situation, I didn't undertsand the code, I tried it but it didn't work 

- DamoDog
-
38 posts
How to create just a single clone
I DID ENTER IT INCORRECTLY!!! IT WORKS!!! THANKYOU SO MUCH!!!
- TheLogFather
-
1000+ posts
How to create just a single clone
EDIT: you ninja'd me… Have you looked at the project? If you haven't, I would suggest looking at it so you can see the situation, I didn't undertsand the code, I tried it but it didn't work

But still read through what I wrote below, since your project is still creating loads of “Sprite1” clones, due to the missing test on the “Your1Spawn” receiver script.
———————–
You still have no test on the broadcast receiver scripts…
The “Your attack” broadcast is unnecessary (at the moment, at least) – get rid of it, and move the “change by -1” block to where you're broadcasting it (i.e. in the touching test).
Add this test in the “Your1Spawn” receiver, to ensure that *only* the original sprite is creating a clone:
TBH, you don't even really need the “Your1Spawn” broadcast (at the moment) – all you need to do is replace that broadcast in the “1 Spawner” sprite with “create clone of Sprite1”, so avoiding the problem with multiple clones receiving the broadcast…
Last edited by TheLogFather (June 1, 2017 13:31:37)
- DamoDog
-
38 posts
How to create just a single clone
EDIT: you ninja'd me… Have you looked at the project? If you haven't, I would suggest looking at it so you can see the situation, I didn't undertsand the code, I tried it but it didn't work
But still read through below, since your project is still creating loads of “Sprite1” clones, due to the missing test on the “Your1Spawn” receiver script.
———————–
You still have no test on the broadcast receiver scripts…
The “Your attack” broadcast is unnecessary (at the moment, at least) – get rid of it, and move the “change by -1” block to where you're broadcasting it (i.e. in the touching test).
Add this test in the “Your1Spawn” receiver, to ensure that *only* the original sprite is creating a clone:
TBH, you don't even really need the “Your1Spawn” broadcast (at the moment) – all you need to do is replace that broadcast in the “1 Spawner” sprite with “create clone of Sprite1”, so avoiding the problem with multiple clones receiving the broadcast…
Have alook at it now, does this work also?
- Discussion Forums
- » Help with Scripts
-
» How to create just a single clone