Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do you know a position of a clone?
- Padabudup
-
Scratcher
10 posts
How do you know a position of a clone?
I created a clone, and when it hits another one, I need a rectangle to be at it's position. How can I know the position of the clone?
- Trixie987
-
Scratcher
100+ posts
How do you know a position of a clone?
when I start as a clone//use this hat block to use a clone
forever
set [clone x v] to (x position)
set [clone y v] to (y position)
end
- Padabudup
-
Scratcher
10 posts
How do you know a position of a clone?
that dosen't work because it shows the positions of the original sprite
- cIoudyness
-
Scratcher
500+ posts
How do you know a position of a clone?
that definitely shows the clone’s position (x and y positions, as well as volume, direction, stuff like that - they act like local variables where each clone has its own copy independent of every other entity; that’s why you can turn two clones in different directions)
perhaps move the clone away from the original sprite or check that you’re using a when I start as clone hat block
perhaps move the clone away from the original sprite or check that you’re using a when I start as clone hat block
- Collin_The_Newmaker
-
Scratcher
100+ posts
How do you know a position of a clone?
There's a more complex thing if you want really many clones.
It assumes that all clones have their ID.
It assumes that all clones have their ID.
when I start as a cloneThe “~” symbol acts as a divider for both x and y positions
forever
replace item (clone id) of [All clones positions v] with (join (x position) (join [~] (y position)))
end
define get position of a clone (clone ID)
set [string v] to []
set [i v] to [1]
repeat until <(item (i) of [All clones positions v] :: list) = [~]>
set [string v] to (join (string) (item (i) of [All clones positions v] :: list))
change [i v] by [1]
end
set [return clone x pos v] to (string)
set [string v] to []
change [i v] by [1]
repeat until <(item (i) of [All clones positions v] :: list) = []>
set [string v] to (join (string) (item (i) of [All clones positions v] :: list))
change [i v] by [1]
end
set [return clone y pos v] to (string)
- cIoudyness
-
Scratcher
500+ posts
How do you know a position of a clone?
it might just be less work just to use two lists. if we have the positions we can just pass them into lists as is instead of causing pain later
i used to be of the mindset that variables and lists were bad and you should reduce them whenever possible, but that’s just a lot more work for little payoff
i used to be of the mindset that variables and lists were bad and you should reduce them whenever possible, but that’s just a lot more work for little payoff
- Collin_The_Newmaker
-
Scratcher
100+ posts
How do you know a position of a clone?
Its hard for me to accept the fact that a dozen of almost useless variables in the code are free and don't bring pain lol
- Collin_The_Newmaker
-
Scratcher
100+ posts
How do you know a position of a clone?
even if its about really useful solutions that require pressing “create a new list” button.
- LOJMOSESrobloxplayer
-
Scratcher
28 posts
How do you know a position of a clone?
There's a more complex thing if you want really many clones.Another thing you can do.
It assumes that all clones have their ID.when I start as a cloneThe “~” symbol acts as a divider for both x and y positions
forever
replace item (clone id) of [All clones positions v] with (join (x position) (join [~] (y position)))
enddefine get position of a clone (clone ID)
set [string v] to []
set [i v] to [1]
repeat until <(item (i) of [All clones positions v] :: list) = [~]>
set [string v] to (join (string) (item (i) of [All clones positions v] :: list))
change [i v] by [1]
end
set [return clone x pos v] to (string)
set [string v] to []
change [i v] by [1]
repeat until <(item (i) of [All clones positions v] :: list) = []>
set [string v] to (join (string) (item (i) of [All clones positions v] :: list))
change [i v] by [1]
end
set [return clone y pos v] to (string)
when green flag clicked
set [(Clone id)] to [1]
when I start as a clone
change [Clone id] by (1)
when I start as a clone
if <(Clone id) = [1]> then
forever
set [Clone 1 x] to (x position)
set [Clone 1 y] to (y position)
end
end
Depending on how many clones you have, you can duplicate that script, for example, if you have 2 clones than it would look something like this:
when green flag clicked
set [(Clone id)] to [1]
when I start as a clone
change [Clone id] by (1)
when I start as a clone
if <(Clone id) = [1]> then
forever
set [Clone 1 x] to (x position)
set [Clone 1 y] to (y position)
end
end
when I start as a clone
if <(Clone id) = [2]> then
forever
set [Clone 2 x] to (x position)
set [Clone 2 y] to (y position)
end
end
Last edited by LOJMOSESrobloxplayer (Aug. 8, 2022 19:43:38)
- Collin_The_Newmaker
-
Scratcher
100+ posts
How do you know a position of a clone?
What if you'd had 1337 clones, ignoring Scratch's clone limit? A ton of work to do and variables to make.
- cactus_bob
-
Scratcher
100+ posts
How do you know a position of a clone?
no but actually, idk if this was mentioned before but if you assign the clone ID a “for this sprite only” thing, there will be a unique value for each clone so you will be able to get the position with just two variables no matter how many clones you have
- Collin_The_Newmaker
-
Scratcher
100+ posts
How do you know a position of a clone?
no but actually, idk if this was mentioned before but if you assign the clone ID a “for this sprite only” thing, there will be a unique value for each clone so you will be able to get the position with just two variables no matter how many clones you haveHow do you adress this value then if you have 3 clones, with each one having a variable “my x” and “my y” for this sprite only?
(actually, instead of making a variable “my x” and “my y”m you can use
([x position v] of [Sprite1 v]),
but that won't work if you want to get x position of a clone)
- legendary34678
-
Scratcher
1000+ posts
How do you know a position of a clone?
You can always use a list to store all of the X and Y positions in.
- blablablahello
-
Scratcher
1000+ posts
How do you know a position of a clone?
that dosen't work because it shows the positions of the original spriteUse “For this sprite only” variables, and you would have a variable PER clone
- legendary34678
-
Scratcher
1000+ posts
How do you know a position of a clone?
Hey, blablablahello! People have already explained that Padabudup should use a For this sprite only variable above. Please check to see if other people have said something similar to what you have in mind before posting. Thanks!
- Sboosh_Kaboosh
-
Scratcher
100+ posts
How do you know a position of a clone?
Make variable for clone x and clone y. Make both for this sprite only.
This should work
when green flag clicked
set [ clone x] to [0]
set [ clone y] to [0]
when I start as a clone
forever
set [ clone x] to (x position)
set [ clone y] to (y position)
say (join (clone x) (join [, ] (clone y))
end
This should work
- Padabudup
-
Scratcher
10 posts
How do you know a position of a clone?
ok, I get it. you can stop posting now. But the project will be a bit later, maybe it will come out in a few weeks or decades. Maybe go code yourself. 

- Discussion Forums
- » Help with Scripts
-
» How do you know a position of a clone?









