Issues with Clone ID
id: 752928
category: Help with Scripts
posts: 9
Inkquire
loading
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:
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
loading
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.
DashDav
loading
Have you checked the command ‘left’?
Inkquire
loading
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)
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
loading
Try adding a “wait 0 seconds” before you create clones, you could have conflicting scripts.
Inkquire
loading
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
loading
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!
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!
-TUB-
loading
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.
Inkquire
loading
Sorry for late reply!
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.
This was the issue, tysm!!
Appreciate all the help everyone ^^
for this sprite onlyJust double check that the cloneID variable is
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.
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 ^^