Discuss Scratch

Inkquire
Scratcher
4 posts

Issues with Clone ID

Hey there! I've been coding a project and having issues with giving directions to specific clones.

My goal is to have two arrow buttons– one for left and one for right. When the left button is clicked, it should broadcast “left,” and when the right button is clicked it should broadcast “right.”

I'm running into an issue where my button continues to broadcast right, even if I click the left side. This is my first time using clones, not sure what the issue is ^^" I've already got working buttons on a very similar code, only major difference I can see is that it's three buttons instead of two, but I've tested it and each receives the instructions I send it

Obviously this isn't a huge issue since I can just make another sprite, but I was curious as to why it wasn't working for me ^^

This is the relevant code:

when green flag clicked
hide
set y to (-40)
delete (all) of [xposition]
set [ID] to [0]
add [-203] to [xposition]
add [203] to [xposition]

when I receive [a command that tells me i need to appear]
show
repeat (2)
change [ID] by (1)
create clone of [myself]
next costume
end

when I start as a clone
show
set x to (item (x) of [x] :: list)

when this sprite clicked
if <[ID] = [1]> then
broadcast [left]
end
if <[ID] = [2]> then
broadcast [right]
end
Malicondi
Scratcher
1000+ posts

Issues with Clone ID

Can you share the project and link it here? There's a chance the problem could be somewhere else in your code that you haven't shown here.

post #1000 post #100 i help in the forums post #1 post #500 0 second ninja
I recommend reading jvvg's essay about the scratch team before complaining, as it may change your opinion and provide insight on the topic.

coming soon :)


Inkquire
Scratcher
4 posts

Issues with Clone ID

Malicondi wrote:

Can you share the project and link it here? There's a chance the problem could be somewhere else in your code that you haven't shown here.

Unfortunately I can't share it at the moment, but I'm keeping the old code in the project. I'll bump the thread when I've finished ^^ (within this week)

DashDav wrote:

Have you checked the command ‘left’?

Sort of– in addition to the “left” broadcast I had a variable assigned that would be assigned with one value if the sprite with ID 1 was clicked and different if the sprite with ID 2 was clicked. It would only output the value for ID 2


Thanks both for the fast replies ^^
kanomaster
Scratcher
100+ posts

Issues with Clone ID

Try adding a “wait 0 seconds” before you create clones, you could have conflicting scripts.
Inkquire
Scratcher
4 posts

Issues with Clone ID

kanomaster wrote:

Try adding a “wait 0 seconds” before you create clones, you could have conflicting scripts.

Tried it! Didn't work unfortunately, but great idea– it's probably related to something like this
MrKingofScratch
Scratcher
100+ posts

Issues with Clone ID

Just double check that the cloneID variable is for this sprite only

It's an easy thing to miss

(for all sprites will make all clones “share” the variable (they all have the same value for the variable; when one updates it, all see the update) and for this sprite only will give all the clones separate instances of the variable (each clone can have a different value for the variable))

We want for this sprite only when using clone IDs, because otherwise the clones would all share the same ID!

Last edited by MrKingofScratch (April 7, 2024 07:38:06)


Last edited by kaj (Tomorrow 00:00:00)
100th post!
-TUB-
Scratcher
100+ posts

Issues with Clone ID

Make sure your main sprite is hidden after cloning, it might be that the main sprite is over the left button and is in front of the clone. When it is clicked, it would trigger the right broadcast because the ID is 2 for the main sprite.

- T U B -
The United Bathtubs


Select part of my signature and use shift+down arrow to see the rest





Inkquire
Scratcher
4 posts

Issues with Clone ID

Sorry for late reply!

MrKingofScratch wrote:

Just double check that the cloneID variable is for this sprite only

It's an easy thing to miss

(for all sprites will make all clones “share” the variable (they all have the same value for the variable; when one updates it, all see the update) and for this sprite only will give all the clones separate instances of the variable (each clone can have a different value for the variable))

We want for this sprite only when using clone IDs, because otherwise the clones would all share the same ID!

Good point– this wasn't this issue but I"ll definitely keep an eye out for the future and make sure my clone variables are local.

-TUB- wrote:

Make sure your main sprite is hidden after cloning, it might be that the main sprite is over the left button and is in front of the clone. When it is clicked, it would trigger the right broadcast because the ID is 2 for the main sprite.

This was the issue, tysm!!

Appreciate all the help everyone ^^

Powered by DjangoBB