Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do I make a clone go to a clone?
- UltimateBlacksmith
-
Scratcher
47 posts
How do I make a clone go to a clone?
I'm making a game where there's a spaceship that attacks by shooting bullets. However, I can't figure out how to script such a thing considering there's no button for sensing clones. The sprite is called Oval. I found many posts about this but couldn't understand them completely with my level of expertise.
Here's the link to the project: https://scratch.mit.edu/projects/508471137
Here's the link to the project: https://scratch.mit.edu/projects/508471137
- cegasm
-
Scratcher
6 posts
How do I make a clone go to a clone?
The project is unshared by the way, have you tried using the clone number method?
- The_Imaginarium
-
Scratcher
1000+ posts
How do I make a clone go to a clone?
Add the clone positions to a list.
- Ji1mmyB
-
Scratcher
100+ posts
How do I make a clone go to a clone?
The other two people ahead of me are exactly right. But you may not know what that means so I will explain. A list is like a variable that just holds data in a numbered list. When you create a clone you will need a “For This Sprite Only” variable that will assign each clone a number or name. So it would look something like this:
Now we return to lists. You'll probably want two list. One for a Clones X point and another for the Clones Y point. What we are doing, is setting each clones X and Y point in a list. So instead of the go to X Y block we are changing the X and Y value in the list and then setting the position to that value in the list. The code would look like this:
What is happening is first when the clone starts we add the two starting positions for that clone. We then have a forever loop that is sensing for the WASD keys to be pressed. If they are pressed then they will change the X and Y values in the list. Then after anything has been changed we will move the clone accordingly. The use for this is that you can now get a clones position from the list to move to another clone. Now just remember thought that the Clone# variable is referring to what clone and this variable needs to be a For this sprite only. I really hoped this helped.
when I receive [Example]What this does is it will first set the variable to 1 then repeat a certain amount of times. Each repetitions will create a clone but the variable changes. So when the clone is created it will remember that number. So when we created clone number 1 we had Clone# at 1. But for clone number 2 Clone# was at 2. So even if you change the variable anywhere else, that number will be same for that clone. So Clone# would equal 1 for clone 1 while Clone# would equal 2 for clone 2. This is a very important step.
set [Clone#] to [1]
repeat (Number of Clones to Create)
create clone of [myself]
change [Clone#] by (1)
end
Now we return to lists. You'll probably want two list. One for a Clones X point and another for the Clones Y point. What we are doing, is setting each clones X and Y point in a list. So instead of the go to X Y block we are changing the X and Y value in the list and then setting the position to that value in the list. The code would look like this:
when I start as a clone
add [Starting X Point] to [CloneX]
add [Starting Y Point] to [CloneY]
forever
if <key [W] pressed?> then
replace item (Clone#) of [CloneY] with ((item (Clone#) of [CloneY] :: list) + (2))
end
if <key [S] pressed?> then
replace item (Clone#) of [CloneY] with ((item (Clone#) of [CloneY] :: list) + (-2))
end
if <key [D] pressed?> then
replace item (Clone#) of [CloneX] with ((item (Clone#) of [CloneX] :: list) + (2))
end
if <key [A] pressed?> then
replace item (Clone#) of [CloneX] with ((item (Clone#) of [CloneX] :: list) + (-2))
end
go to x: (item (Clone#) of [CloneX] :: list) y: (item (Clone#) of [CloneY] :: list)
end
What is happening is first when the clone starts we add the two starting positions for that clone. We then have a forever loop that is sensing for the WASD keys to be pressed. If they are pressed then they will change the X and Y values in the list. Then after anything has been changed we will move the clone accordingly. The use for this is that you can now get a clones position from the list to move to another clone. Now just remember thought that the Clone# variable is referring to what clone and this variable needs to be a For this sprite only. I really hoped this helped.
- UltimateBlacksmith
-
Scratcher
47 posts
How do I make a clone go to a clone?
The other two people ahead of me are exactly right. But you may not know what that means so I will explain. A list is like a variable that just holds data in a numbered list. When you create a clone you will need a “For This Sprite Only” variable that will assign each clone a number or name. So it would look something like this:when I receive [Example]What this does is it will first set the variable to 1 then repeat a certain amount of times. Each repetitions will create a clone but the variable changes. So when the clone is created it will remember that number. So when we created clone number 1 we had Clone# at 1. But for clone number 2 Clone# was at 2. So even if you change the variable anywhere else, that number will be same for that clone. So Clone# would equal 1 for clone 1 while Clone# would equal 2 for clone 2. This is a very important step.
set [Clone#] to [1]
repeat (Number of Clones to Create)
create clone of [myself]
change [Clone#] by (1)
end
Now we return to lists. You'll probably want two list. One for a Clones X point and another for the Clones Y point. What we are doing, is setting each clones X and Y point in a list. So instead of the go to X Y block we are changing the X and Y value in the list and then setting the position to that value in the list. The code would look like this:when I start as a clone
add [Starting X Point] to [CloneX]
add [Starting Y Point] to [CloneY]
forever
if <key [W] pressed?> then
replace item (Clone#) of [CloneY] with ((item (Clone#) of [CloneY] :: list) + (2))
end
if <key [S] pressed?> then
replace item (Clone#) of [CloneY] with ((item (Clone#) of [CloneY] :: list) + (-2))
end
if <key [D] pressed?> then
replace item (Clone#) of [CloneX] with ((item (Clone#) of [CloneX] :: list) + (2))
end
if <key [A] pressed?> then
replace item (Clone#) of [CloneX] with ((item (Clone#) of [CloneX] :: list) + (-2))
end
go to x: (item (Clone#) of [CloneX] :: list) y: (item (Clone#) of [CloneY] :: list)
end
What is happening is first when the clone starts we add the two starting positions for that clone. We then have a forever loop that is sensing for the WASD keys to be pressed. If they are pressed then they will change the X and Y values in the list. Then after anything has been changed we will move the clone accordingly. The use for this is that you can now get a clones position from the list to move to another clone. Now just remember thought that the Clone# variable is referring to what clone and this variable needs to be a For this sprite only. I really hoped this helped.
Thanks for the help, but what are those dark red ovals in the script and how do I access them? Also, I want the sprite to do everything itself and not require any keys to be pressed.
- SuperPickles252
-
Scratcher
9 posts
How do I make a clone go to a clone?
Have you tried using your mouse to find the positiom of the clone
- UltimateBlacksmith
-
Scratcher
47 posts
How do I make a clone go to a clone?
Have you tried using your mouse to find the positiom of the clone
Yes but the clone moves and I need to figure out how to make the clone touch (sense) the other clone.
- UltimateBlacksmith
-
Scratcher
47 posts
How do I make a clone go to a clone?
Wait never mind, what I meant was I need the bullet clone to go to the ship clone. Which means I need it to fire bullets.
- AksharPremnath
-
Scratcher
500+ posts
How do I make a clone go to a clone?
Clones can't sense other clones and can't report their x position and y position so you could do this:
example:
Other clones can reference that list.
example:
when I start as a clone
go to x: (20) y: (5)
if <key [right arrow v] pressed?> then
change x by (10)
replace item (clone ID :: variables) of [list v] with (join (join ((20) + (10)) [,]) [5])
end
Other clones can reference that list.
Last edited by AksharPremnath (April 9, 2021 14:09:44)
- AksharPremnath
-
Scratcher
500+ posts
How do I make a clone go to a clone?
Wait never mind, what I meant was I need the bullet clone to go to the ship clone. Which means I need it to fire bullets.
See this Scratch Wiki article if that is what you wnat.
- dolphin_____hero
-
Scratcher
44 posts
How do I make a clone go to a clone?
I'm making a game where there's a spaceship that attacks by shooting bullets. However, I can't figure out how to script such a thing considering there's no button for sensing clones. The sprite is called Oval. I found many posts about this but couldn't understand them completely with my level of expertise.create variables called “is clone” <–(for this sprite only), “clone x”, “clone y”.
Here's the link to the project: https://scratch.mit.edu/projects/508471137
when i start as a clone
set [ is clone] to [1]
set [ clone x] to (x position)
set [ clone y] to (y position)
broadcast[go to clone]
when i receive[go to clone]
if <(is clone) = [1]> then
go to x(clone x) y(clone y)
end
How does this work?
Since clones can receive broadcasts, just like the sprite, we need to decide if the sprite is a clone or if the clone is a clone. In order to do that, we can make a variable called “is clone” (for this sprite only) and set it to 1 for the clone. Since it is a this sprite only variable, it will not be effected globally to the game, but only to the certain clone. This means that when a clone is created, it will set the variable “is clone” to 1 (true). after setting clone x and y to the clones' x and y position, it will broadcast “go to clone.” when the sprite receives that, it will ask “am i a clone (is clone = 1)? if it does, then i will move to clone x and y.” Because it is a for sprite only variable, like i said before, it will only be for the certain sprite. Hopefully I just didn't confuse you and this actually helped!

- AksharPremnath
-
Scratcher
500+ posts
How do I make a clone go to a clone?
I'm making a game where there's a spaceship that attacks by shooting bullets. However, I can't figure out how to script such a thing considering there's no button for sensing clones. The sprite is called Oval. I found many posts about this but couldn't understand them completely with my level of expertise.create variables called “is clone” <–(for this sprite only), “clone x”, “clone y”.
Here's the link to the project: https://scratch.mit.edu/projects/508471137when i start as a clone
set [ is clone] to [1]
set [ clone x] to (x position)
set [ clone y] to (y position)
broadcast[go to clone]
when i receive[go to clone]
if <(is clone) = [1]> then
go to x(clone x) y(clone y)
end
How does this work?
Since clones can receive broadcasts, just like the sprite, we need to decide if the sprite is a clone or if the clone is a clone. In order to do that, we can make a variable called “is clone” (for this sprite only) and set it to 1 for the clone. Since it is a this sprite only variable, it will not be effected globally to the game, but only to the certain clone. This means that when a clone is created, it will set the variable “is clone” to 1 (true). after setting clone x and y to the clones' x and y position, it will broadcast “go to clone.” when the sprite receives that, it will ask “am i a clone (is clone = 1)? if it does, then i will move to clone x and y.” Because it is a for sprite only variable, like i said before, it will only be for the certain sprite. Hopefully I just didn't confuse you and this actually helped!
I am pretty sure that
(x position), (y position) and (direction) :: greyonly report the parent sprite's. I'll test if what I think is the case.
Edit: I am wrong, the clone said its x position and y position and the parent sprite said its x position and y position both correctly, The clones was 20, 20 and the parent sprite's was 0, 0.
As you can see:

I moved the parent sprite and the clone to a different x and y position so you can see it better.
Last edited by AksharPremnath (April 9, 2021 14:45:33)
- dolphin_____hero
-
Scratcher
44 posts
How do I make a clone go to a clone?
I'm making a game where there's a spaceship that attacks by shooting bullets. However, I can't figure out how to script such a thing considering there's no button for sensing clones. The sprite is called Oval. I found many posts about this but couldn't understand them completely with my level of expertise.create variables called “is clone” <–(for this sprite only), “clone x”, “clone y”.
Here's the link to the project: https://scratch.mit.edu/projects/508471137when i start as a clone
set [ is clone] to [1]
set [ clone x] to (x position)
set [ clone y] to (y position)
broadcast[go to clone]
when i receive[go to clone]
if <(is clone) = [1]> then
go to x(clone x) y(clone y)
end
How does this work?
Since clones can receive broadcasts, just like the sprite, we need to decide if the sprite is a clone or if the clone is a clone. In order to do that, we can make a variable called “is clone” (for this sprite only) and set it to 1 for the clone. Since it is a this sprite only variable, it will not be effected globally to the game, but only to the certain clone. This means that when a clone is created, it will set the variable “is clone” to 1 (true). after setting clone x and y to the clones' x and y position, it will broadcast “go to clone.” when the sprite receives that, it will ask “am i a clone (is clone = 1)? if it does, then i will move to clone x and y.” Because it is a for sprite only variable, like i said before, it will only be for the certain sprite. Hopefully I just didn't confuse you and this actually helped!
I am pretty sure that(x position), (y position) and (direction) :: greyonly report the parent sprite's. I'll test if what I think is the case.
No, they do not! I see why you'd say that, but they are for the sprite only. If you click the check by the variables, it says (sprite name): x position, which means it is a variable can be separated by the clone from the original sprite.
Edit: Tutorial here: https://scratch.mit.edu/projects/513407645/
Last edited by dolphin_____hero (April 9, 2021 14:42:12)
- UltimateBlacksmith
-
Scratcher
47 posts
How do I make a clone go to a clone?
I'm making a game where there's a spaceship that attacks by shooting bullets. However, I can't figure out how to script such a thing considering there's no button for sensing clones. The sprite is called Oval. I found many posts about this but couldn't understand them completely with my level of expertise.create variables called “is clone” <–(for this sprite only), “clone x”, “clone y”.
Here's the link to the project: https://scratch.mit.edu/projects/508471137when i start as a clone
set [ is clone] to [1]
set [ clone x] to (x position)
set [ clone y] to (y position)
broadcast[go to clone]
when i receive[go to clone]
if <(is clone) = [1]> then
go to x(clone x) y(clone y)
end
How does this work?
Since clones can receive broadcasts, just like the sprite, we need to decide if the sprite is a clone or if the clone is a clone. In order to do that, we can make a variable called “is clone” (for this sprite only) and set it to 1 for the clone. Since it is a this sprite only variable, it will not be effected globally to the game, but only to the certain clone. This means that when a clone is created, it will set the variable “is clone” to 1 (true). after setting clone x and y to the clones' x and y position, it will broadcast “go to clone.” when the sprite receives that, it will ask “am i a clone (is clone = 1)? if it does, then i will move to clone x and y.” Because it is a for sprite only variable, like i said before, it will only be for the certain sprite. Hopefully I just didn't confuse you and this actually helped!
I assume I have to make these in the enemy bullet sprite?
- dolphin_____hero
-
Scratcher
44 posts
How do I make a clone go to a clone?
Yes.I'm making a game where there's a spaceship that attacks by shooting bullets. However, I can't figure out how to script such a thing considering there's no button for sensing clones. The sprite is called Oval. I found many posts about this but couldn't understand them completely with my level of expertise.create variables called “is clone” <–(for this sprite only), “clone x”, “clone y”.
Here's the link to the project: https://scratch.mit.edu/projects/508471137when i start as a clone
set [ is clone] to [1]
set [ clone x] to (x position)
set [ clone y] to (y position)
broadcast[go to clone]
when i receive[go to clone]
if <(is clone) = [1]> then
go to x(clone x) y(clone y)
end
How does this work?
Since clones can receive broadcasts, just like the sprite, we need to decide if the sprite is a clone or if the clone is a clone. In order to do that, we can make a variable called “is clone” (for this sprite only) and set it to 1 for the clone. Since it is a this sprite only variable, it will not be effected globally to the game, but only to the certain clone. This means that when a clone is created, it will set the variable “is clone” to 1 (true). after setting clone x and y to the clones' x and y position, it will broadcast “go to clone.” when the sprite receives that, it will ask “am i a clone (is clone = 1)? if it does, then i will move to clone x and y.” Because it is a for sprite only variable, like i said before, it will only be for the certain sprite. Hopefully I just didn't confuse you and this actually helped!
I assume I have to make these in the enemy bullet sprite?
- UltimateBlacksmith
-
Scratcher
47 posts
How do I make a clone go to a clone?
Yes.It's still not working.
- AksharPremnath
-
Scratcher
500+ posts
How do I make a clone go to a clone?
No, they do not!
Yeah, you're right. I tested it. But when you show the x position and y position on the screen when checking them in the Motion section, it only shows the parent sprite's but you could show the clone's as a variable:
when I start as a clone
go to x: (20) y: (20)
say (join (join (x position :: motion) [ and ]) (y position :: motion))
set [x position v] to (join (join (join [Clone ] (clone ID :: variables)) [of Sprite1: ]) (x position :: motion))
set [y position v] to (join (join (join [Clone ] (clone ID :: variables)) [of Sprite1: ]) (y position :: motion))
show variable [x position v]
show variable [y position v]
- AksharPremnath
-
Scratcher
500+ posts
How do I make a clone go to a clone?
Yes.It's still not working.
Replace
when green flag clickedin the Enemy Bullet sprite with:
hide
when green flag clicked
hide
set [is clone v] to [0]
- UltimateBlacksmith
-
Scratcher
47 posts
How do I make a clone go to a clone?
Yes.It's still not working.
Replacewhen green flag clickedin the Enemy Bullet sprite with:
hidewhen green flag clicked
hide
set [is clone v] to [0]
I'm sorry but nothing is happening. How will this trigger the oval ship to shoot bullets?
Last edited by UltimateBlacksmith (April 10, 2021 15:26:29)
- Discussion Forums
- » Help with Scripts
-
» How do I make a clone go to a clone?