My experiment has drag and drop objects feature, and at the same time a textbox containing clicked object’s name is expected to show up when the mouse click on that object. I was able to implement this feature by creating a textbox and conditioned on when $mouse.isPressedIn(clickable). Attached is how I coded.
christmas_lights.psyexp (26.2 KB)
However, unexpected behavior occurs. Only when the last element in clickable list (created at begin routine) is clicked, in this case is “star”, the textbox will show up and the rest names will also show up when clicked. But If the other item is clicked first, say “b1”, nothing happen until the “Star” is clicked.
I also re-arrange the order of the clickable list, which proves my assumption that only if the last element is clicked the textbox will show. This is very odd to me, no idea how to fix this. I really appreciated any help! Thanks!
Begin Routine clickables = [b1, b2, b3, star] for clickable in clickables: clickable.dragging = False drag_in_progress = False
for clickable in clickables: if clickable.dragging and sum(mouse.getPressed()) > 0: clickable.setPos(mouse.getPos()) displayName_text.setPos(mouse.getPos() + 0.05) if clickable.dragging and sum(mouse.getPressed()) == 0: clickable.dragging = False drag_in_progress = False displayName = "" if not drag_in_progress and not clickable.dragging and mouse.isPressedIn(clickable): clickable.dragging = True drag_in_progress = True displayName = clickable.name displayName_text.setPos(mouse.getPos()+0.05)
displayName is also placed in the textbox which is conditioned on $mouse.isPressedIn(clickable)