Discuss Scratch

SewCool
Scratcher
100+ posts

X and Y position of clones

Hi! Just a quick question…

Is it possible to sense the X and Y position of a clone, or even to have the parent sprite go to the same position as the clone in order to record it? Thanks!
Sinaboo
Scratcher
100+ posts

X and Y position of clones

You can store the X and Y position of a clone with something like this
when I start as a clone
forever
set [x v] to (x position)
set [y v] to (y position)
end

Last edited by Sinaboo (March 31, 2019 02:23:37)

Tallented-Code-bot
Scratcher
100+ posts

X and Y position of clones

Sinaboo wrote:

You can store the X and Y position of a clone with something like this
when green flag clicked
forever
set [x v] to (x position)
set [y v] to (y position)
end
instead of that, it should be
when green flag clicked
create clone of[myself v]

when I start as a clone
forever
set[X v]to(x position)
set[Y v]to(y position)
end
-ShadowOfTheFuture-
Scratcher
1000+ posts

X and Y position of clones

If you only have one clone, create 2 global (“for all sprites”) variables, “clone x” and “clone y” or whatever you want to name them. Then add a script under a “when I start as a clone” block that makes the clone constantly set the values of those variables to its own x and y positions - the respective motion blocks report those values for the clone when they're used under the clone hat block. Finally, make the parent sprite constantly set its x and y positions to the values of “clone x” and “clone y”.

If you have multiple clones, you can accomplish pretty much the same thing using a list instead of 2 variables.
Denki_Lover394
Scratcher
1 post

X and Y position of clones

none of the ideas worked
christian1227
Scratcher
1 post

X and Y position of clones

Is it supposed to be a “For this sprite only” or no?
Apple-pie-slice
Scratcher
1 post

X and Y position of clones

Yeah…

They don't work when you have 15 clones…

So could somebody help me with that!
B1j2754
Scratcher
78 posts

X and Y position of clones

Edit: Realized I added to a necropost, and this was an old and abandoned post. I apologize.

One potential solution I have used in the past is the following steps:
- Create a private variable called “cloneID”
- Create a list called “Clone Coordinates”
- Write the following code:

when green flag clicked
delete all of [Clone Cordinates v]
set [cloneID v] to [0]
repeat (5)
change [cloneID v] by (1)
create clone of [myself v]
end
set [cloneID v] to [-1]

when I start as a clone
add (cloneID) to [Clone Coordinates v]
add (0) to [Clone Coordinates v]
add (0) to [Clone Coordinates v]
forever
replace item ((item # of (cloneID) in [list v]) + (1)) of [Clone Cordinates v] with (x position)
replace item ((item # of (cloneID) in [list v]) + (2)) of [Clone Cordinates v] with (y position)
end

And then you can reference each clone's x and y through their ID's position in “Clone Coordinates” plus 1 or 2, depending on if you want x or y

ALSO, if you want to receive broadcasts, and have only clones do this, or only want clones to do something, you can do something like this:

when I receive [move up v]
if <not <(cloneID) = [-1]>> then
change y by (10)
end

And you can also specify a subset of clones to do this with a very similar method

Last edited by B1j2754 (Dec. 12, 2024 02:31:18)

Powered by DjangoBB