Fixed trial order with randomized critical trials

Hi all,

I am trying to build an experiment that will be deployed on pavlovia. In this experiment I want to have a fixed trial order except for the critical trials.

There will be 100 trials. The stimuli for 88 trials will be fixed, so a particular image is shown during a particular trial. I know when the remaining 12 trials will be, but not what stimulus will be shown. I want to randomly assign the stimulus that is shown.

I saw this topic: Stop a routine. but I don’t think it will work. I could also do this very crudely and create individual routines for 88 trials, but that seems a bit ridiculous.

Any thoughts or advice?

Assuming your 12 trials and at a fixed point in the 100 could you have three consecutive loops (two sequential and one random pointing at different rows in your spreadsheet) with all loops surrounding copies of the same trial routines.

Thanks for the reply.

The 12 trials are at fixed points during the 100 trial sequence. Is this what you are talking about when you mentioned consecutive loops?

Screen Shot 2022-01-16 at 2.37.16 PM

Close

The trial_2 Routine should be a second instalment of the trial routine and I’m not sure what the trials_3 loop is doing.

Okay cool, I had another idea but I am not sure if psychopy will be able to handle it.

What if I set each of the 12 critical trials as individual variables. Could I have one excel trial file that runs sequentially? Would it be able to handle a variable instead of path?

critical_trial1 = "img.jpeg"
imgfile corAns
img1.jpeg 1
img2.jpeg 1
critical_trial1 0

I would do it all in code and not bother with excel files.

import random

fixed_files = ['1.jpg', 'dummy1', '3.jpg', 'dummy2', '5.jpg', 'dummy3', '7.jpg', ]
dummy_indexes = [1,3,5]
random_files = ['a.jpg', 'b.jpg', 'c.jpg']

random.shuffle(random_files)

for i, idx in enumerate(dummy_indexes):
    fixed_files[idx] = random_files[i]
    
print(fixed_files)

then use fixed_files[trials.thisN] on the image component

I now realise that when you said 12 critical trials, you probably didn’t mean a consecutive block of 12 randomised trials. What you are trying to achieve sounds like a prospective memory task, though if so, I’m not sure why you would want the background task to be in a fixed order.

What I do for PM is preload the background and target trials into two lists and then have a trials loop which selects from the appropriate list each trial. One of my PM tasks, called PM Time, is in my Online Demos post.

However, you absolutely could just predefine your 12 target images in a shuffled list (targetfiles) and then have “critical_trial” in your spreadsheet when you want to show them

Use the following code in Begin Routine

thisImage = imgfile
if imgfile == 'critical_trial':
     thisImage = targetfiles.pop()

then set your image as thisImage each repeat (making sure that the image component is below the code component).