Discuss Scratch

scratchcoolbus
Scratcher
8 posts

Finding the Position of a Clone

I am trying to make a tower defense and i need to use the x and y position of a clone but i cant figure it out. Here is my code
add (x position) to [list v]
add (y position) to [list v]

But it is only using the sprite's x and y position, not any of the clone's

Last edited by scratchcoolbus (Sept. 2, 2024 02:38:56)

Jlerpy
Scratcher
1000+ posts

Finding the Position of a Clone

Have you got these inside the “when I start as a clone” section?
bsteichman
Scratcher
500+ posts

Finding the Position of a Clone

you gotta have it inside the clone

create clone of [myself v]
add (x position) to [list v] //this is wrong
meanwhile:

create clone of [myself v]

when I start as a clone
add (x position) to [list v] //this is correct

one thing to note, is that if you're adding their positions onto the list constantly, the list will grow constantly, and the same values won't be updated.
wouldn't it make more sense to use the
replace item ( v) of [list v] with [thing]
block?

so that if your clone has the id of 5, the 5th value will always be updated with the X?

Last edited by bsteichman (Sept. 2, 2024 04:03:03)

scratchcoolbus
Scratcher
8 posts

Finding the Position of a Clone

Thank you so much, ive been at it for such a long time

Edit: this for some reason is only taking the x and y of the original and not any of the clones

Last edited by scratchcoolbus (Sept. 2, 2024 22:28:04)

TheNoisyNoisy
Scratcher
100+ posts

Finding the Position of a Clone

scratchcoolbus wrote:

Thank you so much, ive been at it for such a long time

Edit: this for some reason is only taking the x and y of the original and not any of the clones
ok then, do
when I start as a clone
forever
delete (all v) of [list v]
add (x position) to [list v]
add (y position) to [list v]
end
Woodfur
Scratcher
100+ posts

Finding the Position of a Clone

Is the list itself “for all sprites”? Otherwise each clone will have a copy no other sprite can access.
Jlerpy
Scratcher
1000+ posts

Finding the Position of a Clone

Yes, the list is all sprites, for exactly the reason you say. Otherwise you can't get the clones to report.
deck26
Scratcher
1000+ posts

Finding the Position of a Clone

TheNoisyNoisy wrote:

scratchcoolbus wrote:

Thank you so much, ive been at it for such a long time

Edit: this for some reason is only taking the x and y of the original and not any of the clones
ok then, do
when I start as a clone
forever
delete (all v) of [list v]
add (x position) to [list v]
add (y position) to [list v]
end
Bad idea - only one clone's data will ever be in the lists.
deck26
Scratcher
1000+ posts

Finding the Position of a Clone

I think you need to share the project so we can see what you're doing.
TheNoisyNoisy
Scratcher
100+ posts

Finding the Position of a Clone

deck26 wrote:

TheNoisyNoisy wrote:

scratchcoolbus wrote:

Thank you so much, ive been at it for such a long time

Edit: this for some reason is only taking the x and y of the original and not any of the clones
ok then, do
when I start as a clone
forever
delete (all v) of [list v]
add (x position) to [list v]
add (y position) to [list v]
end
Bad idea - only one clone's data will ever be in the lists.
oops use ids then
scratchcoolbus
Scratcher
8 posts

Finding the Position of a Clone

Yo I cant thank yall enough This time it worked for real
if <chat helpful> then
say [Thank you]
end
scratchcoolbus
Scratcher
8 posts

Finding the Position of a Clone

Sadly i have another problem
i need to find the nearest clone's distance to another clone but its taking the original sprite and not the nearest clone any help?
I Need to use this block:
(distance to [ v Nearest Enemy Clone])

Last edited by scratchcoolbus (Sept. 15, 2024 21:25:42)

codeywhizz
Scratcher
100+ posts

Finding the Position of a Clone

scratchcoolbus wrote:

Sadly i have another problem
i need to find the nearest clone's distance to another clone but its taking the original sprite and not the nearest clone any help?
I Need to use this block:
(distance to [ v Nearest Enemy Clone])
yea ur gonna need some algorithmic thinking for that, literally the best way is to brute force through every combination of 2 clones
TheNoisyNoisy
Scratcher
100+ posts

Finding the Position of a Clone

scratchcoolbus wrote:

Sadly i have another problem
i need to find the nearest clone's distance to another clone but its taking the original sprite and not the nearest clone any help?
I Need to use this block:
(distance to [ v Nearest Enemy Clone])
why would you NEED to use that block?
scratchcoolbus
Scratcher
8 posts

Finding the Position of a Clone

I found an equation using that block that makes my projectile arc but i cant with any other block. this is the equation:
repeat (41)
change x by ((round (distance to [Enemy Clone])) / (41))
change y by (Y Velocity)
end

Unless any of you know a work around

Last edited by scratchcoolbus (Sept. 16, 2024 18:56:52)

Powered by DjangoBB