Switch between left and right presentation location on each new trial

OS (e.g. Win10): win10
PsychoPy version (e.g. 1.84.x): 2022.2.4
Standard Standalone? (y/n) If not then what?: y

Hello Discourse community,

**What are you trying to achieve?:
I am trying to build an experiment in which participants see a reference picture (Master picture) in the top center part of the screen and 2 possible response pictures (Attributional response and Relational response) in the lower half of the screen, on the left and right side. All three pictures are presented simultaneously. I would like that for each trial, Attributional response and Relational response switch places randomly.

Each Master picture goes strictly with the 2 response pictures that go along with it.
I have 6 groups of 3 pictures each (so in total 6 trials).

**What did you try to make it work?
I have managed to randomize the order of picture groups across trials (thanks to the loopType being set to random) but I am still at the stage where Attributional responses are always on the left, Relational responses are always on the right.

I have one image component imageMasterStim that has a fixed location.
And two other image components imageAttributionalResponse and imageRelationalResponse that need to randomly switch locations from left to right on each new trial.

I have this piece of code in the Begin Routine that allows me to read the left and right position coordinates from the Excel sheet, shuffle them and select the first item after shuffling as the current position.

In both image components, I have $positions

I am a bit stuck when it comes to the randomization part.
I feel like I need an if statement, saying something like
If on this trial the shuffled position is PositionLeft, show imageAttributionalResponse on the left and imageRelationalResponse on the right, if the shuffled position is PositionRight, show imageAttributionalResponse on the right and imageRelationalResponse on the left.

But I don’t know exactly how to write it…

I am sorry for asking such a basic and recurrent question, I have read several of the randomization tutorials and posts in the forum, watched the video tutorials, but somehow I am still stuck here. I would be grateful for any help and/or suggestions!

All the best,

Hi @VVV,

I think all you need to do is use $positions[0] for one of the image components and $positions[1] for the other one.

Hi @ajus,

Thanks for your suggestion!
Did you mean it like this?

When I run it like this, it crashes right away with the following error message:

IndexError: list index out of range
################ Experiment ended with exit code 1 [pid:12728]

All the best,

I think you have to delete the line
positions = positions[0:1]

Hi @ajus ,

Thank you, it works perfectly!

All the best,

1 Like

Hi again @ajus,

I have a follow up question, maybe you will be able to help me with this one too.

To synchronize with EEG, I would like to send a trigger via parallel port every time when participants click on one image or the other.

I would like to have one trigger code (let’s say 1) for all the Attributional responses and another trigger code (2) for all the Relational responses.

I have this piece of code in the Begin routine tab but when I open the Excel data sheet, all I have are 0 in the trigger column.

I suppose I am doing doing something wrong in the if statements but I don’t know what exactly…

All the best,

Hi @VVV,

If I understand you correctly, I would do it like this:

Begin routine

trigger = 0 # set trigger to 0 at the beginning of each trial

Every frame

if mouse.isPressedIn(imageAttributionalResponse): # set trigger to 1 if the Attributional Response image is clicked 
    trigger = 1
elif mouse.isPressedIn(imageRelationalResponse): # set trigger to 2 if the Relational Response image is clicked 
    trigger = 2
  • “mouse” is your mouse component

End routine

thisExp.addData('trigger', trigger) # write trigger to the data 

Let me know if this is what you are trying to do!

Hi @ajus

This is almost what I am trying to do, but not exactly.
When I use the code that you suggested, the trigger values are correctly written in the csv data file, depending on which image I clicked on. When I use the print(trigger) command I see in the runner that whenever I click on an Attributional response I get a 1 and when I click on a Relational response I get a 2. Everything is perfect up to here. The problem is that between the triggers of interest I get an enormous amount of zeroes that appear continuously even if I am not clicking on anything (I suppose that’s because a new zero appears at each frame refresh).

This makes me think that the code is not doing exactly what I am looking for.

I have a parallel port component that needs to send a trigger to the EEG device, every time the participant clicks on an Attributional or a Relational image. So when a participant clicks on an Attributional image, the parallel port should send a “1” to the EEG and when a participant clicks on a Relational image, the parallel port should send a “2” to the EEG. Those are the only two moments when a trigger needs to be sent, there’s no need for a continuous feed of zeroes while the participant is thinking.

So, I thought that I should simply take the code that you suggested for the Every frame tab and put it into the Begin routine tab.
However, when I do this, I get only zeroes, both in the csv file and in the runner.

No, trigger is only set to zero at the beginning of the routine. Not every frame. But I suspect that when you click, a new routine begins. So yes, there will be a lot of zeros. I think, the problem is not really in the code, but in how you set the start condition of your Parallel Port Out component. If I understand you correctly, it would have to be the condition trigger is not 0. This way, the component waits until trigger is not 0 anymore and then sends the actual value of trigger. PsychoPy will still print the many zeros if you tell it to, but it won’t send them to the Port Out. Is that what you want it to do?

Or do you want to get one 0 at the beginning of the trial and a 1 or a 2 at the end of the trial? Then trigger is not 0 would have to be the stop condition and the start would be time 0.

Yes, exactly !

Which of the two? :smiley:

Oops, sorry, I think I read before the edit.
The first option would be perfect.

Ok, so do it like this:

  • keep the code as is
  • for the start condition of your Port Out set trigger is not 0
  • if it works fine, make sure to remove the print() commands, because printing every frame is unnecessary

Hi @ajus,

I still haven’t had the chance to test it with EEG but otherwise it seems to work.
Thank you so much for your help for both my questions!


1 Like