Counterbalancing image stimuli

Hi all,

I am relatively new to psychopy and have managed to build a version of my experiment in the builder. I have noticed a counterbalancing issue which I don’t think can be solved using conditions files and likely requires some code. Unfortunately, I don’t have any prior coding experience and I am struggling to apply the basics to this issue.

In the experiment I am creating a visual illusion using image stimulus objects based on the muller lyer illusion (see example below). There are 2 parallel lines displayed in the centre of the screen every trial and ‘tails’ at the end of each line. I have recreated this in the builder using 6 image objects (1 for each parallel line and 4 images for the tails).

ML example

I have used conditions files to vary the length of the top line (and the relative position of the tails) each trial between 5 variants (the baseline length (688 pix), 788 pix, 888 pix, 588 pix and 488 pix) whilst keeping the bottom images constant. However, for counterbalancing purposes I would like to vary this so that either the top OR bottom line could change length in each trial whilst the other remains at the baseline length.

Participants are going to do a 2-alternative forced choice task to determine which line is longer in each trial so I want to eliminate any potential confound of only having 1 line change every trial.
From what I can tell this wouldn’t be possible to do using conditions files as both the top and bottom stimuli would change randomly every repeat.

Here is the current structure of the experiment, showing the set up for the first routine:

and a labelled mockup of the bottom half of the screen:

To make things more complex I am also varying the display of the stimuli so that there are 2 conditions:

  1. where all the images are static (as described above)
  2. where the ‘tails’ at the end of each line flicker in a checkerboard pattern at a rate of approx 4 Hz

I have achieved this flickering effect by creating a second routine with the same structure as before but each stimulus is presented for 0.25 seconds and then looped for 80 repeats. The tails are then set to vary every repeat between 2 colour variants of the same image controlled by a conditions file. The length of the top line is then governed using the same structure as before.
Like this:

Ideally for both routines I want either of the two lines to vary randomly between the 5 possible lengths whilst the other is at the baseline length of 688 pix in each trial. If you have any ideas about how I could counterbalance the order of the routines (i.e static and flickering stimuli types) that would also be helpful.

Thanks in advance!

Are the two lines in your stimulus two separate images? If so then you could have one as an Image component which is always presented and always has the same image file, but whose location varies. You wouldn’t /necessarily/ need a Code component for this, you could use a Variable component (let’s call it locIndex) to define a variable whose Begin Routine value is randint(0,1) - i.e. pick a random number between 0 and 1. Then you could set the position of the base stimulus to be (0, (0.5, -0.5)[locIndex]). In other words, x=0 and y=either 0.5 or -0.5, depending on whether locIndex is 0 or 1. Then for the other stimulus, you could set its position to be (0, (0.5, -0.5)[locIndex-1]), meaning the index is either 0 or -1 (so it will take the opposite value to the one used for your base stim).

That way, you can set your experimental stimulus from your experiment file and keep your base stimulus the same, whilst keeping the position shuffling you want.