Stop/resume loop or call for conditions without for loop?

Hi,

I’m trying to create an experiment where on the 5th trial I can show a different trial. to be more specific i want to show some images 5 times, then i want to show pairs of those images previously shown each fifth image… The images are in an excel file, and the pairs of images are on another excel file. I don’t combine them, because I previously randomized the images and the order of the pairs.
I have two questions: is it possible to use something similar as in R, to call a condition (excel file) within a trial loop without using another loop? if so how can i use it?
for example i have:

conditions = data.importConditions(images.csv) 
conditions2 = data.importConditions(pairsof images.csv)

nReps = 1
trials1 = data.TrialHandler(conditions, nReps, method = "sequential")
pics = visual.ImageStim(win)
words = visual.TextStim(win)

trials2 = data.TrialHandler(conditions2, nReps, method = "sequential")
pic1 = visual.ImageStim(win)
pic2 = visual.ImageStim(win)

for trial in trials1:
etc..

Can i do something like:
“from conditions2” pic1.draw()?

If the above is not possible, I used a for loop with the trials2 in order to use pic1 and pic2, I have to stop the trial otherwise it will show all the pairs without waiting for the next 5th trial.
for that I used trials2.finish= True, and then I say it’s false in order to resume the trials when the condition of the trials being the 5th to show the pairs… The problem is that instead of showing or “resuming” in the second trial (second pair of images), it skips that one and starts with the third pair… I tried using getEarliertrial, but it didn’t work, is there any other solution?

that part of the code looks like this right now.

for trial in trialspav: # this is the first condition
    if trial["Trialnr"] in list:
        trialsquery.finished = False # somehow when I "resume" it skips one row on the excel file
        for n,i in enumerate(list):
            if i %5 ==0:
                list[n] = i + 5
        for trials in trialsquery: #this is my second condition
            print trialsquery.thisIndex #i used this to check what happened and it goes from 0 to 2 to 4... skipink 1 and 3... and so forth
            if trialsquery.thisIndex != 0 and trialsquery.thisIndex %2 == 0:
                #trialsquery.getEarlierTrial(n = -1) #I tried this but it doesn't work 
                #trialsquery.getFutureTrial(1)
                pic1.setImage(trials["Image3"]) #he encounter a pair of stimuli
                pic1.pos = (-.5,0)
                pic2.setImage(trials["Image2"])
                pic2.pos = (.5,0)
                query = mouse_choice (win, True, pic1, pic2) #the person just chooses the highest value, to reinforce learning 
                if query < 0:
                    query = trial["Value"] #because we don't know the order beforehand
                    trialsquery.finished = True
                else:
                    query = trial["Value"]
                    trialsquery.finished= True
                    win.flip()
            else:
                #trialsquery.getEarlierTrial(n = -1) # itried also here, didn't work 
                pic1.setImage(trials["Image3"]) #he encounter a pair of stimuli
                pic1.pos = (-.5,0)
                pic2.setImage(trials["Image2"])
                pic2.pos = (.5,0)
                query = mouse_choice (win, True, pic1, pic2) #the person just chooses the highest value, to reinforce learning 
                if query < 0:
                    query = trial["Value"] #because we don't know the order beforehand
                    trialsquery.finished = True
                else:
                    query = trial["Value"]
                    trialsquery.finished= True
                    win.flip()

I appreciate any suggestions or comments to “fix this”

Thank you in advance.

Hi Andre, would you be able to express your first paragraph more clearly so we know what you want to achieve? e.g. it isn’t clear what “where on the 5th trial I can show a different trial” or " i want to show pairs of those images previously shown each fifth image" mean, at lest to me.

It might also be useful to give some explicit examples of the structure of your two conditions files.

1 Like

Hi Michael,

Sure, I can try to be less unclear.

So basically I want to show a set of images (Pictures variable in excel file 1) and words (value variable excel file1) 50 times, and every 5th image I want to show 2 images (Image2 and Image3 in excel file2) as if comparing them (one besides the other).

for the 50 images and words the excel file1 looks something similar to this:

Trialnr  Value     Pictures
1          +10         x.png
2          +2           y.png
3           -10         z.png
4            -2          a.png
5             0          b.png
6           -2           a.png
7           +10        x.png
...

for the second excel file 2 images shown together:

Image2   Image3
x.png     y.png
y.png     z.png
z.png    a.png
a.png    x.png
b.png    y.png
y.png    b.png
..... ten pairs

Sorry if it was unclear… I hope this clarifies your questions.

Hi Andre, OK I think I get it now. A solution might be something like this:

  1. Have two routines within your loop. One is set to show the image from the Pictures variable plus the text. The next is set up to show the images from the Image2 and Image3 variables.

  2. Insert a code component on each routine to control which routine runs on any given trial number.

e.g. in the first routine, put something like this in the Begin routine tab:

if (your_loop_name.thisN + 1) % 5 == 0:
    continueRoutine = False

and in the second routine:

if (your_loop_name.thisN + 1) % 5 != 0:
    continueRoutine = False 

i.e. here we are using the modulo operator (%) to see what the remainder is when we divide the trial number by 5 (we need to add 1 as the trial numbering starts at 0). i.e. the first trial will run unless the trial number is a multiple of five, and the second will not run unless it is a multiple of five.

Then you should structure your conditions files so that you just have one, with all variables in the same file. i.e. there will be valid image names for Image2 and Image3 only on every fifth row, whereas the Pictures variable will have valid image name on every row.

It is possible that Builder might complain that there is no image for the stimuli on the second routine on some trials (even though they won’t be displayed). If so, just provide a junk placeholder image for those rows in the conditions file.