About clones
clones are extremely helpful in keeping your code clean, along with they can do amazing things including
- make an entire game in 1 object
- generate smooth backgrounds easily and efficiently
- make certain aspects of a game (a shape art, button, etc.)
so why aren’t they used a lot? they can be very confusing.
Cloning Methods
before figuring out clones, let’s look at methods of cloning.
Method 1: Normal Cloning
this is where you just put a repeat loop with create a clone inside:
Pros of Method 1:
- easy
Cons of Method 1:
- slow
- only creates 1 clone at a time
Method 2: Total Cloning
basically in this method you have the clones create clones:
Method 2 explained
self(total clones) means the object’s total clones—which we want 50. every time a clone is made, that clone also makes a clone, and that happens until you get the desired amount of clones you want.
Pros of Method 2:
- quicker
Cons of Method 2:
- a little harder to understand
- can lag up if used in mass amounts
Method 3: Secret Blocks
using JSON editing, we can implement a secret “create a clone times” block that instantaneously creates x amount of clones:
Pros of Method 3:
- extremely quick
- easy to read
Cons of Method 3:
- can be hard to access the block
if you want to get the Create a Clones Times block, view this project by Awesome_E
Method 4:
Clone Index
What is it?
every time a clone is created, it gets an “index” or assigned a number. each clone of an object has a different index, the original object being 1, the first clone 2, second clone 3, etc.
notice that for each individual sprite the clone index starts at 1. this is VERY IMPORTANT.
Why is Clone Index important?
you can control many things with clone index—it’s very helpful. here’s an example:
you’re making a game with 1 object and want to set a variable (Play) to 1 when the button you made that says play is tapped.
Method 1
you could do this and set a boundary to make sure it was the play button that was tapped:
Method 2
or, with knowledge of clone index you could do this and check if the clone that was tapped has an assigned number of 5, 6, or 7:
- method 1 is easier to understand
- method 2 is easier to understand
Making Clones Do Certain Things
this is pretty easy with a knowledge of clone index and doesn’t require an image or example. just do:
when object is cloned {
check once if (clone index = 2) {
set image(square)
} else check once if (clone index = 3) {
set image(circle)
}
}
this means the clone with an index of 2 is a picture of a square, and the clone with an index of 3 is a picture of a circle.
pretty easy, right?
- yes!
- no, I’m confused (reply)
- I understand Clone Index better
- I don’t understand Clone Index better
- I knew clone index before reading but this is helpful
- I knew clone index before reading and this isn’t helpful
(Self) variables
so now that you know clone index, you can control self variables. basically, a self variable only assigns a value to a specific clone
for example:
this means that the clone that is assigned the index 2 has a personal variable called canBeInvisible set to 1. when canBeInvisible = 1 for any clone, that specific clone becomes invisible.
How to reduce lag with mass clones
easy; use the destroy block if the clone won’t be used again. do this by:
when self(canBeDestroyed) = 1 {
set self(canBeDestroyed) to 0 // optional and not necessary
destroy
}
well, I think that covers it, hope this helped and please, let me know if you need help on something or have something to add:)
- I understand clones better now!
- I knew clones before, but this is helpful
- I don’t understand clones better
(omtl was tagged)









