Discuss Scratch

digthebone
Scratcher
500+ posts

the cloning tutorial: the basics of cloning.

Here is an updated version of my cloning tutorial. I made a new one due to multiple spelling errors and it was kind of confusing and hard to follow.

Anyways, if you need to learn about cloning, then most of the info should be right here. Also, don't be embarrassed if you don't know what cloning is! When I started scratch, I had no idea what the heck any of it was!

What Does Cloning Do?

Cloning makes a copy of a sprite in a project. When you make a clone, the clone will stay at the same location of the sprite it copied from and will do nothing. It will do nothing unless you code it to do something, which you will learn if you keep reading.

What to Know When You Clone

Note that you can't make too many clones, because the clone limit is around 300-500 clones. Basically, if you make too many clones it will eventually stop making clones due to the clone limit. The reason for the clone limit is to prevent lag and crashes. Also, even though there is a clone limit, you can't make the clones do too many things or lag will happen.

Basics of Cloning

The basic blocks of cloning is these 3 blocks:

when I start as a clone

create clone of [ v]

delete this clone

The most important of these 3 are
create clone of [ v]

because without that block, you won't be able to make a clone in the first place. So What does that block do? It makes a clone of the sprite you want to make a clone of. When you use this block, it will first appear as
create clone of [myself v]

this means it will create a clone of whatever sprite you are currently coding. Also, if you have multiple sprites, you can make it create a clone of other sprites by clicking the down arrow. After this, you just click whatever sprite you want to make a clone of. example:
create clone of [sprite3 v]
The next important block is
when I start as a clone

with this block, you can make the clone do whatever you want. You just have to add the coding that makes it do something below this block. Note that you can make it do whatever you want it to! Lets say you want the clone to go to a random place:

when I start as a clone
go to [random position v]

and you are done! Maybe you want it to wait some time before it goes to a random position…

when I start as a clone
wait (whatever amount of time you want it to wait) secs
go to [random position v]

That is all you have to do!

Now there is one final important block:

delete this clone

this block can be self explanatory. It deletes the clone. By making a clone delete itself, you can make it stop doing what it is doing and hide forever. By deleting a clone, it doesn't count as a clone anymore, so by deleting a clone you can prevent the clone limit from happening. Note that once you delete a clone, that clone can't come back. Lets say you want the clone to go to a random position, wait some time, then delete itself. You simply do this:

when I start as a clone
go to [random position v]
wait (whatever amount of time you want it to wait) secs
delete this clone

Of course, you don't have to make it go to a random position, wait, and delete itself. You can make it do whatever you want it to.

Making Multiple Clones

To make a sprite make multiple clones, you have to use the repeat block.

repeat ()

end

With this block, you can make a sprite make a specific amount of clones. Lets say you want to make 30 clones. You just do this:

repeat (30)
create clone of [whatever sprite you are making a clone of v]

end

It really is very simple. Of course, you can make any amount of clones you want, as long as it is not too much to bypass the clone limit. There is also another block you can use, which is the forever block.

forever

end

To make it always be making a clone, you do this:

forever
create clone of [whatever sprite you are making a clone of v]
end

You can make the sprite do whatever you want it to before you havee it make a clone. lets say you want it to go to a random place before you have it make another clone:

forever
create clone of [whatever sprite you are making a clone of v]
go to [random position v]

end

You can make it do anything, not just go to a random position. You can also do that with the repeat block. Note that if you are always making a clone, the clone will eventually have to delete itself or the clone limit will become a problem.

Conclusion

There is many other things you can do with cloning, but for the basics, that is it! Now you know that you can do pretty much anything with cloning, as long as it doesn't exceed the clone limit. If you have a question about cloning, you can ask me in this topic or ask someone else that might know. Final note: make sure you use the green flag block before you do any of this! (or the broadcast block or custom block if you know what i'm talking about) Hope this helped!

Questions I can answer in this post
I recently added this section since there are common questions about cloning that have a short and simple answer.

1. What is the difference between stamping and cloning?

If you don't know what the stamping block is, it's this:

stamp

What stamping does is create an exact replica of the sprite. The problem is stamping is you cant make a stamped clone do anything, and the only way to clear a stamped sprite is by using the

clear

block. This will delete every single stamped sprite though. The only real benefit with stamping is that it doesnt have a max limit like cloning does.

I will add more questions and answers in this section as I see or think of them. Thank for reading!

Last edited by digthebone (Jan. 24, 2019 22:24:11)


Digthebone

I make stuff. And I am always digging for new idea's.




LoudHeadphones
Scratcher
100+ posts

the cloning tutorial: the basics of cloning.

To add to this (almost sticky worthy) tutorial, here is how you make multiple clones of the same sprite that do different things:

First you create your clones of course
when green flag clicked
set [ID v] to [1]
repeat (3)
create clone of [myself v]
change [ID v] by (1)
end
NOTE: When you create the variable ID you must check the box that says “for this sprite only”

Now to apply this ID of the clone, we do this
when I start as a clone
if <(ID) = [1]>
go to x: (100) y: (100)
else
if <(ID) = [2]>
go to x: (-100) y: (-100)
else
go to x: (0) y: (0)
end
end
So you can see this “ID” for each clone changes each time you create one. The reason that they don't all read the ID as the same number is because it's “for this sprite only” which means that each clone stores that variable by its self so only that clone can change the variable for that clone.

Hope that makes sense to you readers learning about the wonderful world of cloning.

This has been LHP. The dude that makes chiptune music ranging from “Meh” to “Nice” and then puts it in a studio
Do you want somebody to tell you what they think goes into good platformers? No? Well then don't view this project
digthebone
Scratcher
500+ posts

the cloning tutorial: the basics of cloning.

LoudHeadphones wrote:

To add to this (almost sticky worthy) tutorial, here is how you make multiple clones of the same sprite that do different things:

First you create your clones of course
when green flag clicked
set [ID v] to [1]
repeat (3)
create clone of [myself v]
change [ID v] by (1)
end
NOTE: When you create the variable ID you must check the box that says “for this sprite only”

Now to apply this ID of the clone, we do this
when I start as a clone
if <(ID) = [1]>
go to x: (100) y: (100)
else
if <(ID) = [2]>
go to x: (-100) y: (-100)
else
go to x: (0) y: (0)
end
end
So you can see this “ID” for each clone changes each time you create one. The reason that they don't all read the ID as the same number is because it's “for this sprite only” which means that each clone stores that variable by its self so only that clone can change the variable for that clone.

Hope that makes sense to you readers learning about the wonderful world of cloning.
that is another way of doing it. you can also just look at the “multiple clones” section and the “making clones of another sprite” section and you can just mix them together. But please don't do other tutorials in my tutorial,i mainly want questions.

Digthebone

I make stuff. And I am always digging for new idea's.




InCrIpToNiX
New to Scratch
1 post

the cloning tutorial: the basics of cloning.

LoudHeadphones wrote:

To add to this (almost sticky worthy) tutorial, here is how you make multiple clones of the same sprite that do different things:

First you create your clones of course
when green flag clicked
set [ID v] to [1]
repeat (3)
create clone of [myself v]
change [ID v] by (1)
end
NOTE: When you create the variable ID you must check the box that says “for this sprite only”

Now to apply this ID of the clone, we do this
when I start as a clone
if <(ID) = [1]>
go to x: (100) y: (100)
else
if <(ID) = [2]>
go to x: (-100) y: (-100)
else
go to x: (0) y: (0)
end
end
So you can see this “ID” for each clone changes each time you create one. The reason that they don't all read the ID as the same number is because it's “for this sprite only” which means that each clone stores that variable by its self so only that clone can change the variable for that clone.

Hope that makes sense to you readers learning about the wonderful world of cloning.

what if i want to have 100+ clones doing different things? i dont have time for all that scripting…
digthebone
Scratcher
500+ posts

the cloning tutorial: the basics of cloning.

InCrIpToNiX wrote:

LoudHeadphones wrote:

To add to this (almost sticky worthy) tutorial, here is how you make multiple clones of the same sprite that do different things:

First you create your clones of course
when green flag clicked
set [ID v] to [1]
repeat (3)
create clone of [myself v]
change [ID v] by (1)
end
NOTE: When you create the variable ID you must check the box that says “for this sprite only”

Now to apply this ID of the clone, we do this
when I start as a clone
if <(ID) = [1]>
go to x: (100) y: (100)
else
if <(ID) = [2]>
go to x: (-100) y: (-100)
else
go to x: (0) y: (0)
end
end
So you can see this “ID” for each clone changes each time you create one. The reason that they don't all read the ID as the same number is because it's “for this sprite only” which means that each clone stores that variable by its self so only that clone can change the variable for that clone.

Hope that makes sense to you readers learning about the wonderful world of cloning.

what if i want to have 100+ clones doing different things? i dont have time for all that scripting…
if you don't want to do a bunch of scripting this would be pretty much impossible. You can make the clones doing few things different. Just do this.
create a variable
(variable)  //you can name it whatever you want
now do this
when green flag clicked
forever // you dont have to make it go forever you could make it only make some clones.

create clone of [myself v]
end
now you do this:
when I start as a clone
if <(variable) = [1 ]> then
repeat until <touching [edge v] ?>
move (10) steps
end
if <(variable) = [2 ]> then
repeat until <touching [edge v] ?>
move (10) steps
change [color v] effect by (1)
end
if <(variable) = [3 ]> then
repeat until <touching [edge v] ?>

change x by (10)
move (-5) steps
end

end

end


end
delete this clone
and finally…
when green flag clicked
forever

set [variable v] to [(pick random (1) to (3) ]
end
also you don't have to make it do that stuff you can make the clones do whatever you want.

Last edited by digthebone (March 7, 2017 16:12:48)


Digthebone

I make stuff. And I am always digging for new idea's.




WOWCrAzY000
Scratcher
7 posts

the cloning tutorial: the basics of cloning.

Is it possible for the clones to interact with one another (I'm trying to do an if statement when two different clones touch)
Koopakid6000
Scratcher
100+ posts

the cloning tutorial: the basics of cloning.

This could be like the sticky that explains everything you need to know about scratchblocks, include info like:
The number the clone limit is (which I believe is 300 but I heard you can hack it so that there are more)
The fact that the clone limit isn't the only time delete this clone comes in handy
The fact that clicking the stop sign or green flag deletes all clones
The fact that clones are affected by all hat blocks accept when green flag clicked because that must happen before clone generation.
To the clone and the cloned sprites, clones are not sprites, however it is the opposite to other sprites.
Too many clones can cause lag, so try to limit how many are on screen (hidden but existing is considered ‘on screen’).

Hope this helps

Last edited by Koopakid6000 (April 20, 2016 23:32:18)


define Awesome 
Koopakid6000 ::operators

undefined //I lost my coding purpose so now I destroy kumquats.












Paddle2See
Scratch Team
1000+ posts

the cloning tutorial: the basics of cloning.

I added this to the list of helpful topics!

Scratch Team Member, kayak and pickleball enthusiast, cat caregiver.

This is my forum signature! On a forum post, it is okay for Scratchers to advertise in their forum signature. The signature is the stuff that shows up below the horizontal line on the post. It will show up on every post I make.
(credit to Za-Chary)



;
asivi
Scratcher
1000+ posts

the cloning tutorial: the basics of cloning.

Koopakid6000 wrote:

This could be like the sticky that explains everything you need to know about scratchblocks, include info like:
The number the clone limit is (which I believe is 300 but I heard you can hack it so that there are more)
The fact that the clone limit isn't the only time delete this clone comes in handy
The fact that clicking the stop sign or green flag deletes all clones
The fact that clones are affected by all hat blocks accept when green flag clicked because that must happen before clone generation.
A clone that does nothing is the same as a stamp
To the clone and the cloned sprites, clones are not sprites, however it is the opposite to other sprites.
Too many clones can cause lag, so try to limit how many are on screen (hidden but existing is considered ‘on screen’).

Hope this helps
It isn't.
Koopakid6000
Scratcher
100+ posts

the cloning tutorial: the basics of cloning.

asivi wrote:

Koopakid6000 wrote:

This could be like the sticky that explains everything you need to know about scratchblocks, include info like:
The number the clone limit is (which I believe is 300 but I heard you can hack it so that there are more)
The fact that the clone limit isn't the only time delete this clone comes in handy
The fact that clicking the stop sign or green flag deletes all clones
The fact that clones are affected by all hat blocks accept when green flag clicked because that must happen before clone generation.
To the clone and the cloned sprites, clones are not sprites, however it is the opposite to other sprites.
Too many clones can cause lag, so try to limit how many are on screen (hidden but existing is considered ‘on screen’).

Hope this helps
It isn't.
Fixed it

define Awesome 
Koopakid6000 ::operators

undefined //I lost my coding purpose so now I destroy kumquats.












Xx__xXloganXx__xX
Scratcher
23 posts

the cloning tutorial: the basics of cloning.

What specifically is the clone limit? Im making a game that involves alot of clones.
awesome-llama
Scratcher
1000+ posts

the cloning tutorial: the basics of cloning.

I think your post is too stretched out and it should be more concise. I agree with Koopakid6000, that some information is missing. Also add that local variables are clone's unique variables

Xx__xXloganXx__xX wrote:

What specifically is the clone limit? Im making a game that involves alot of clones.
301.

mbhyat wrote:

gkgk
That is spam. Please don't do it.

Last edited by awesome-llama (April 21, 2016 03:59:42)



f_deruvo
Scratcher
100+ posts

the cloning tutorial: the basics of cloning.

Hi all
may I ask about clones how is possible to get the distance between two clones? Is it not easy like distance between two sprite.. Thanks

Adv: Guess-who (game) - Marrakech (game) - Info-map (tool)
Habity
Scratcher
17 posts

the cloning tutorial: the basics of cloning.

Hmm… Here's my dilemma. In a game I'm working on, one of the enemies shoots at you, BUT this enemy is a clone, and the projectiles that it fires don't come from it, but rather from the original sprite. Suggestions on fixing this?

Last edited by Habity (March 6, 2017 23:22:55)

asivi
Scratcher
1000+ posts

the cloning tutorial: the basics of cloning.

Habity wrote:

Hmm… Here's my dilemma. In a game I'm working on, one of the enemies shoots at you, BUT this enemy is a clone, and the projectiles that it fires don't come from it, but rather from the original sprite. Suggestions on fixing this?
Yes i suggest you to create your own topic and share the project where such behavior happens, and don't forget to talk in detail about any relevant stuff involved in.
Habity
Scratcher
17 posts

the cloning tutorial: the basics of cloning.

asivi wrote:

Habity wrote:

Hmm… Here's my dilemma. In a game I'm working on, one of the enemies shoots at you, BUT this enemy is a clone, and the projectiles that it fires don't come from it, but rather from the original sprite. Suggestions on fixing this?
Yes i suggest you to create your own topic and share the project where such behavior happens, and don't forget to talk in detail about any relevant stuff involved in.
Sounds like a good idea to me. Thanks for the advice!
digthebone
Scratcher
500+ posts

the cloning tutorial: the basics of cloning.

Paddle2See wrote:

I added this to the list of helpful topics!

Digthebone

I make stuff. And I am always digging for new idea's.




digthebone
Scratcher
500+ posts

the cloning tutorial: the basics of cloning.

accidentally quoted my main post

Last edited by digthebone (March 7, 2017 16:15:59)


Digthebone

I make stuff. And I am always digging for new idea's.




digthebone
Scratcher
500+ posts

the cloning tutorial: the basics of cloning.

f_deruvo wrote:

Hi all
may I ask about clones how is possible to get the distance between two clones? Is it not easy like distance between two sprite.. Thanks
first record the x and y coordinates of the first clone. Then the second. subtract the x coordinate by the other x and the y coordinate by the other y and you should have your answer.

Digthebone

I make stuff. And I am always digging for new idea's.




deck26
Scratcher
1000+ posts

the cloning tutorial: the basics of cloning.

digthebone wrote:

f_deruvo wrote:

Hi all
may I ask about clones how is possible to get the distance between two clones? Is it not easy like distance between two sprite.. Thanks
first record the x and y coordinates of the first clone. Then the second. subtract the x coordinate by the other x and the y coordinate by the other y and you should have your answer.
Try to check the date of the post you're responding to! I doubt they were still waiting for a response.

Powered by DjangoBB