Drag and drop anywhere on screen, i.e not in preset polygon

OS (e.g. Win10): WIN 10
PsychoPy version (e.g. 1.84.x): 3
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?:

I am designing an object location task where:

  1. the participant is shown objects in their correct location in an exposure phase (which is done and works fine).
  2. they are then shown the object at the centre of the screen
  3. they then have to drag the object to where the think the object belongs (i.e., where they were shown it previously)
  4. A trial is classed as correct if the object is within 150 pixels of its original location.

What did you try to make it work?:

I’ve tried to figure out the drag and drop demo, which is similar but a bit different so have struggled.

i’ve searched through the forum for any relevant threads and nothing quite covers what i’m stuck on.

still looking on OSF for any similar studies.

Any help greatly appreciated.

Best wishes,
Tom

Hi Tom,

You described what you are trying to do but haven’t actually stated what your issue is.

Hi Michael,

Thanks for getting back to me
.
The issue simply is that I don’t know how to do it - I’ve been through lots of resources (past forum threads, psychopy manual,osf framework,repository,drag and drop demos) and still don’t know how I’m supposed to do it.

If someone could show me an example or a template for how to do that would be so helpful.

The builder is great but whenever it comes to putting code components in I get lost.

Best wishes,
Tom

Simple drag and drop is quite straightforward. Simply insert a code component on your routine, and in the “Each frame” tab, put something like:

if mouse.isPressedIn(your_stimulus_name):
    your_stimulus_name.pos = mouse.getPos()

I guess you will also want to record the location in the data, so in the “End routine” tab, put something like:

thisExp.addData('response_x', your_stimulus_name.pos[0])
thisExp.addData('response_y', your_stimulus_name.pos[1])
1 Like

Awesome Michael, thanks i’ll have a play about with the code you sent.

Best wishes,
Tom