Millisecond Forums

dragging pictures for working memory study

https://forums.millisecond.com/Topic15847.aspx

By charlottebooth - 3/26/2015

I want to create a working memory task where participants will be shown an image/(s) on the screen - they then complete a distractor task - and then see two images and they have to drag the one they have previously seen to the same location where it was before.

The problem I'm having is planning how to drag the image to the desired location.

I have looked at the Tower of London Task - but would like a bit of a hint as to which element is causing the dragging feature.

Many thanks!

By Dave - 3/26/2015

The dragging feature in the ToL script works as follows:

Once you've selected one of the balls in <trial choice>, it executes a /branch to <trial move>. <trial move> is what chiefly implements the dragging feature. It accepts mouse movement and a left-click as response.

<trial move>
...
/ validresponse = (mousemove,lbuttondown)
/ branch = [if(trial.move.response=="mousemove")trial.move else trial.check]
</trial>

As long as the mouse is moved, <trial move> is repeated over and over again. If a left-click occurs, <trial check> is invoked, which (1) establishes whether the chosen action is valid (i.e., is there a free spot on the selected peg or not?) and if so (2) places the ball in the correct position.

Hope this helps.
By charlottebooth - 3/29/2015

Thank you for your help, but I think I am still a bit lost. Do you know of a less complicated task in the library that uses a dragging feature? It would be good if they had some more tutorials that were a bit more advanced perhaps.
By Dave - 3/29/2015

No, there isn't a less complicated example in the library. If you can point out what exactly you're having trouble with, I'll gladly try to explain.

By Dave - 3/29/2015

Here's a bare-bones, self-contained example illustrating the basic mechanics. It's just a few lines of code and, as you'll see, not hard to understand:

<values>
/ itemnumber = 1
/ x = 50%
/ y = 50%
</values>

<expressions>
/ xpct = 100pct*(trial.movemearound.responsex/display.width)
/ ypct = 100pct*(trial.movemearound.responsey/display.height)
</expressions>


<block myblock>
/ trials = [1=pickmeup]
</block>

<trial pickmeup>
/ ontrialbegin = [values.itemnumber=1]
/ inputdevice = mouse
/ stimulusframes = [1=blank, mystimulus]
/ validresponse = (mystimulus)
/ branch = [trial.movemearound]
</trial>

<trial movemearound>
/ ontrialbegin = [values.itemnumber=2]
/ ontrialend = [values.x = expressions.xpct; values.y = expressions.ypct]
/ inputdevice = mouse
/ stimulusframes = [1=blank, mystimulus]
/ validresponse = (mousemove, lbuttondown)
/ numframes = 1
/ branch = [if (trial.movemearound.response!="lbuttondown") trial.movemearound else trial.pickmeup]
</trial>

<text mystimulus>
/ items = ("Click me to pick me up.", "Click the left mouse button to put me down.")
/ select = values.itemnumber
/ size = (20%, 20%)
/ hposition = values.x
/ vposition = values.y
/ txbgcolor = red
/ erase = false
</text>

<shape blank>
/ shape = rectangle
/ size = (100%, 100%)
/ erase = false
</shape>

By charlottebooth - 3/30/2015

Thank you so much - I should be able to work from this to start making my task!

Charlotte
By charlottebooth - 3/31/2015

Could I just ask a few minor things?
1) why do you need the blank stimulus?
2) in trial.movearound. why do you put the '!' after trial.move.response.?
3) what are the expressions doing?


Thanks!!

C
By Dave - 3/31/2015

> 1) why do you need the blank stimulus?

Otherwise you'd be seeing a trace of the stimulus' previous movements (it is set to /erase=false; if it were set to /erase=true, it'd be flickering). Try it for yourself.

> 2) in trial.movearound. why do you put the '!' after trial.move.response.?

"!=" is a negation. See the "Operators" topic in the documentation for details.

if (trial.movemearound.response!="lbuttondown") trial.movemearound else trial.pickmeup

means "if the response in trial movearound is *not* a click on the left mouse button, run trial moveraround again. Otherwise run trial pickmeup."

> 3) what are the expressions doing?

They convert the mouse x and y coordinates to screen percentages for convenience.
By charlottebooth - 3/31/2015

That's great thank you.
Now I have created my own file with a target and distractor picture. The participant should be able to choose either one and drag to a location. As the script is below - this only works when the choice of picture was the target. For some reason when you pick the distractor this also branches on to the trial.correctmove. Any ideas?

<values>
/ a = 50%
/ b = 40%
/ c = 50%
/ d = 60%
</values>

<expressions>
/ apct = 100pct*(trial.correctmove.responsex/display.width)
/ bpct = 100pct*(trial.correctmove.responsey/display.height)
/ cpct = 100pct*(trial.incorrectmove.responsex/display.width)
/ dpct = 100pct*(trial.incorrectmove.responsey/display.height)
</expressions>

<shape blank>
/ shape = rectangle
/ size = (100%, 100%)
/ erase = false
</shape>

<picture target>
/items = ("target1.tif")
/size = (100,100)
/hposition = values.a
/vposition = values.b
/erase = false
</picture>

<picture distract>
/items = ("distract1.tif")
/size = (100, 100)
/hposition = values.c
/vposition = values.d
/erase = false
</picture>


<text move>
/ items = ("Move target to correct location")
/position = (50, 50)
/ txbgcolor = red
/ erase = false
</text>

<trial choice>
/inputdevice = mouse
/stimulusframes = [1=blank, target, distract, move]
/validresponse = (target, distract)
/branch = [if(trial.choice.response!=target) trial.correctmove]
/branch = [if(trial.choice.response!=distract) trial.incorrectmove]
</trial>

<trial correctmove>
/inputdevice = mouse
/stimulusframes = [1=blank, target]
/validresponse = (mousemove, lbuttondown)
/numframes = 1
/ontrialend = [values.a = expressions.apct; values.b = expressions.bpct]
/ branch = [if (trial.correctmove.response!="lbuttondown") trial.correctmove]
</trial>

<trial incorrectmove>
/inputdevice = mouse
/stimulusframes = [1=blank, distract]
/validresponse = (mousemove, lbuttondown)
/numframes = 1
/ontrialend = [values.c = expressions.cpct; values.d = expressions.dpct]
/ branch = [if (trial.incorrectmove.response!="lbuttondown") trial.incorrectmove]
</trial>

<block one>
/trials = [1=choice]
</block>

By Dave - 3/31/2015

I'm pretty sure <trial choice> should actually read

<trial choice>
/inputdevice = mouse
/stimulusframes = [1=blank, target, distract, move]
/validresponse = (target, distract)
/branch = [if(trial.choice.response=="target") trial.correctmove]
/branch = [if(trial.choice.response=="distract") trial.incorrectmove]

</trial>