Drag and drop adaptation: moving the pieces all as one

OS (e.g. Win10): mac OS Catalina version 10.15.7
PsychoPy version (e.g. 1.84.x): 3.2
Standard Standalone? (y/n) Yes
**What are you trying to achieve?:
I am looking to adapt the drag and drop demo so that the dragged stimulus moves all as one with no pieces left behind. However the attached version create several pieces which means that as you drag one piece away the next piece is available underneath.

What did you try to make it work?:
I have started adapting so that I am only using one stimulus (whitePiece) and I have positioned it 0,0 as this is where I need it to be for my experiment (see my adapted demo attached). I have disabled the other components because they are not useful to me.

My understanding in the original demo is that the image stimulus is updated each frame in order to move and a new stimulus (piece) is re-drawn in the starting position of the piece you have just moved.

What specifically went wrong when you tried that?:
I attempted to use the createPiece() function in Begin routine so that a new piece would be made on each trial but this led to the experiment not running (with no error message).

My other idea was to alter the createPiece function (in Begin Experiment)- I think this is the area of code I need to change in order to achieve what I am looking for but I’m unsure what I could do instead of the current set up.

Psychopy file and conditions file (see original drag and drop demo in the builder demos for images and more info):
dragAndDropEditedVersion.psyexp (38.3 KB)

conditions.xlsx (8.7 KB)

If you don’t need to create new pieces, I think you can remove createPiece altogether! You just need to have something to get mouse position on click and something to move the piece. Here’s a super minimal example:
dragDrop.psyexp (7.1 KB)

1 Like

Okay, thank you. I will give that a go :slight_smile:

That works now. Thank you very much! :slight_smile:
Just for the future reference of other people the Java scrip syntax is:

if (mouse.isPressedIn(polygon)) {
    polygon.pos = mouse.getPos()
}

I received a syntax error because the if statement was missing a ‘)’