# Randomisation of image position (with certain feedback) between subjects

Hi everyone!

I have an experiment that involves presenting two images, participant clicks one of them and a feedback (points) with certain probability appears. The feedback is different for each image. There are 6 loops each containing different pair of images leading to a specific feedback for that image, and there are 100 trials in each loop.

Is it possible to present the images bounded to certain feedback in random location (right vs. left) between participants, but keep the location constant for each participant?

I tried this: in the routine AFTER participant made a choice, I put the code component for certain feedback to appear:

keys = event.getKeys()

if response.keys == âleftâ and left11 == âred.pngâ:
hpos = [-0.5,0]
deckshown = 'redHIGH.pngâ
unchosenpoints = 1.5
unchosendeck = 'grey.pngâ
unchosenpos = [0.5, 0]
pointswon = points

elif response.keys == âleftâ and left11 == âgrey.pngâ:
hpos = [-0.5,0]
deckshown = 'greyHIGH.pngâ
unchosenpoints = points
unchosendeck = 'red.pngâ
unchosenpos = [0.5, 0]
pointswon = 1.5

if response.keys == ârightâ and right11 ==âgrey.pngâ:
hpos = [0.5,0]
deckshown = 'greyHIGH.pngâ
unchosenpoints = points
unchosendeck = 'red.pngâ
unchosenpos = [-0.5, 0]
pointswon = 1.5

elif response.keys == ârightâ and right11 == âred.pngâ:
hpos = [0.5,0]
deckshown = 'redHIGH.pngâ
unchosenpoints = 1.5
unchosendeck = 'grey.pngâ
unchosenpos = [-0.5, 0]
pointswon = points

But I get an error :

File âC:\Users\u1664328\Dropbox\1. Alina\Project\Computational and Mathematical Modeling of Behaviour and Cognition\1.My Project\2. Description-Told Group\DescriptionTold.pyâ, line 492, in
image.setPos(unchosenpos)
NameError: name âunchosenposâ is not defined

There are a number of reasons why the `unchosenpos` variable can be undefined at the time it is referenced.

In this case, the most likely reason is that none of your conditional statements are executed. `event.getKeys()` returns a list, even for a single key press (hence `getKeys` rather than `getKey`). So you should do a test like this:

``````if 'left' in keys:
``````

rather than:

``````if keys == 'left': # will always be untrue as keys is a list
``````

Also note that you are mixing references to your own variable `keys` and some other variable `response.keys`. Which one are you actually wanting to test?

1 Like

Thank you very much for your reply, Michael!

I need to test `response` key from `Trial` routine. I have the code that I described above in `highlight_2` routine on top of other components.

In `block1` loop there is an .xlsx file that specifies the odds of getting certain points for each image for 100 trials:

I tied this:
1.

``````
if 'left' in keys and left11 == 'red.png':
``````

Get Error:

``````Description-Told Group\DescriptionTold.py", line 500, in <module>
image.setPos(unchosenpos)
NameError: name 'unchosenpos' is not defined
``````
``````keys = event.getKeys()

if 'left' in response.keys and left11 == 'red.png':
``````

Get Error:

``````##### Running:
pyo version 0.8.0 (uses single precision)
Traceback (most recent call last):
Description-Told Group\DescriptionTold.py", line 469, in <module>
if 'left' in response.keys and left11 == 'red.png':
TypeError: argument of type 'NoneType' is not iterable
Traceback (most recent call last):
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\app\coder\coder.py, line 2638, in copy
foc.Copy()
AttributeError: 'AuiTabCtrl' object has no attribute 'Copy'
``````

My question:
I canât get my head around how can I randomise the location of two images (that are bound to certain odds of getting points) between participants. Is there a way?
Also, what should I put in `image` and `location` for `left11` and `right11` images in Trial routine?

OK,

• Bonus points for drawing the red arrows.
• This line should deleted as you are using a keyboard component to check for keypresses:
``````keys = event.getKeys()
``````
• Because you are using a keyboard component rather than `event.getKeys()`, and presumably have it set to react to just a single key, you should indeed go back to using:
``````if response.keys == 'left'
``````

as the keyboard component does just return a single key in that situation rather than a list (hence the error about about not being able to iterate.

• Lastly, Iâm not sure where `'red.png'` comes from (as it isnât in your conditions file), but you canât test whether an image component (`left11`) is equal to a string of characters representing a filename. They are quite different beasts. Iâm not sure what is really desired here, but probably you want to check whether the filename associated with that image component is `'red.png'`, in which case, I think you need to do something like this:
``````if left11.image == 'red.png'
``````

But presumably you know which image files are being used for the stimuli if they arenât varying (i.e. coming from a conditions file), so not really sure what this test is for.

I donât really understand your questions in the last paragraph, as they are very broad. Perhaps just resolve your issues one a time before introducing other things.

Thanks, Michael!

My questions in the last paragraph are the main ones that I try to overcome with the code. That is, put the images (âred.pngâ or âgrey.pngâ) in the random location in `Trial` and then, depending on the location and the choice of a participant, show a feedback with certain probability.

Can I somehow randomise all 12 images (for 6 different lotteries) across all loops, in a way that, for example:

• Participant 1 gets red image (or yellow or green) on the right, and grey (or purple or blue) image on the left. If he chooses ârightâ in this trial, he gets 5 points in 100% times. If he chooses âleftâ, he gets 6 points with 90% chance or 0 points otherwise. Red and grey images should stay in these positions for all 100 trials, bound to the same feedback and never appear in the next loops.

• Participant 2 gets grey image (or yellow or green) on the right and red (or purple or blue) image on the left. Again, for example, if he chooses ârightâ, he gets 5 points in 100% times. If he chooses âleftâ, he gets 6 points with 90% chance or 0 otherwise. Again, the pictures should stay in these position for all 100 trials, bound to the same feedback and not appear in the next loops.

So, it doesnât matter which colour is bound to which feedback, but itâs important that itâs consistent for one participant for all 100 trials, doesnât occur again in the consequent loops and changes for the next participant.

Iâm not sure what code and where should I put it to implement this randomisation between participants.