Yes, this will take code. Firstly, set the balanced but randomised order of conditions:
trial_types = ['image', 'word'] * 80
shuffle(trial_types)
Secondly, set the order within the images, which is easy:
image_list = [f'image_{i}.jpg' for i in range(80)]
shuffle(image_list)
Then set the order of words, which is trickier. I’m going to cheat here and randomise it within blocks of 20, meaning we just have to check that there is no consecutive repetition between the last entry of one block of 20 and the first of the next one:
original_words = ['cat', 'dog', 'frog', 'walrus', 'kiwi'] # you'll have 20 words here
shuffle(original_words)
word_list = []
word_list.extend(original_words)
for _ in range(4):
# prevent first word of next list being the same as the last word of the previous:
last_word = word_list[-1]
original_words.remove(last_word)
shuffle(original_words)
first_word = original_words[0]
word_list.append(first_word)
# randomise and append the next 19 words:
original_words.remove(first_word)
original_words.append(last_word)
shuffle(original_words)
word_list.extend(original_words)
# restore the list to 20 words:
original_words.append(last_word)
I haven’t tested that code, but hopefully it would give you a list of 80 words, randomised within 4 blocks, with no consecutive entries.
Now you need to create two routines, one to show a text stimulus and one to show an image stimulus. Surround them both with a single loop, set to have an nReps
of 160.
To control which routine runs on any given trial, insert a code component on each one. In the “begin routine” tab of the image routine, put something like this:
trial_type = trial_types[your_loop_name.thisN]
if trial_type == 'word':
continueRoutine = False
else:
image_name = image_list.pop()
thisExp.addData('trial_type', trial_type)
thisExp.addData('image_name', image_name)
and this in the word routine:
trial_type = trial_types[your_loop_name.thisN]
if trial_type == 'image':
continueRoutine = False
else:
word = word_list.pop()
thisExp.addData('trial_type', trial_type)
thisExp.addData('word', word)
and set the text stimulus component’s content to be $word
and the image field to be $image_name
, set to update on every repeat.