| Reference | Downloads | Github

Alternate between image_stim and text_stim

Hi everyone,
I am trying to build an IAT task. I explain everything to be as clear as possible :

This is my routine “trial”.

We can see two loops : 1. blocks and 2. trials

  1. Blocks refers to an xlsx file :

    In this file, we find condition file (7 conditions), left and right label (to categorize) and instruction (appears un ready routine)

  2. In trials, I have each condition file, we find :

    StimImage and StimWord with image reference and words. Some condition have only image or only text, for training condition.

Everything works perfectly but I have one problem : in condition with image AND text, I need to alternate between this two type of stimuli (picture/text/picture/text/…) but still in a random way and I really don’t know how to code it. Do you have any idea ?

Please define your randomisation scheme precisely, as you would in a methods section. Your requirements are not clear at the moment. e.g. if it is random, how can it also alternate?

Sorry !
For example, there are 20 words and 20 images. I would like to alternate between words and images but the images / words selection in this 20 images / words is random.

OK. That won’t be possible using a single conditions file - if you set the loop to be random, it will shuffle all of the rows and you won’t be able to ensure an alternation of conditions between rows.

It would be possible using custom code, or using a more complicated structure in Builder. Let’s go with the latter route for the moment:

  • You will need two routines, one to show an image and one to show a word.
  • Each of those routines will need to be surrounded with its own loop, called, say, image_trials and word_trials.
  • Each of those loops is connected to a separate conditions file, one to control words, and one to control the images.
  • Surround the two inner loops with another loop. This is not connected to a conditions file, but just given an nReps value of 20. It goes in between your trials and blocks loops.

So what you need to do now is arrange for each of the inner loops to only run one iteration rather than loop through all 20 rows of the conditions file in one go, but you need to ensure that all 20 rows are eventually consumed, with no repetition. We can do this by creating two lists of indices that pseudo-randomly select just one row per iteration of the outer loop. So insert a code component (from the “custom” component panel), on any routine. In its “begin experiment” tab, put something like this:

image_order = range(20) # indices 0 through 19
shuffle(image_order)    # in randomised order

word_order = range(20)

Then in the “selected rows” field of your inner loops, put:





This should give you alternation between trial types, while randomising the order of chosen stimuli, without any repetition.

You will need to alter your blocks conditions file accordingly, so that it now controls two conditions files per block, rather than just one, because you have now split the words and images into separate files.

Hello Ilona,
thank you for your code! Unfortunately, it’s not working for me. I think because the range and shuffle function isn’t working… You mentioned another option using code. Could you maybe eloborate on that?

Thank you very much!