Presenting images in a loop

Hi all,

I wonder if anyone can tell me whats wrong with this code. What I want to achieve is for 6 faces to appear on screen, around a fixation cross, in 12 trials. These 12 trials will be split into two blocks of 6-a deceptive block and a truthful block. However, as far as the experiement running goes, the message is displaying, then the fixation cross which is good. However, it is crashing after this (and therefore the loop). Please see attached the error message.

The code is:

        message6 = visual.TextStim(win, text = "Are any of these people involved in the incident?")
        message6.draw()
        win.update()
        response = event.waitKeys(keyList = ['space',], timeStamped = True)#this will wait for a button press confirmation from p's to continue
        
        #This section creates the trials
        
        Matrix = [[0 for x in xrange(6)] for x in xrange(6)]
        
        
        Matrix[0][0] = 1
        Matrix[0][1] = 2
        Matrix[0][2] = 5
        Matrix[0][3] = 6
        Matrix[0][4] = 7
        Matrix[0][5] = 8
        
        Matrix[1][0] = 1
        Matrix[1][1] = 3
        Matrix[1][2] = 9
        Matrix[1][3] = 11
        Matrix[1][4] = 7
        Matrix[1][5] = 12
        
        Matrix[2][0] = 1
        Matrix[2][1] = 4
        Matrix[2][2] = 9
        Matrix[2][3] = 12
        Matrix[2][4] = 6
        Matrix[2][5] = 10
        
        Matrix[3][0] = 2
        Matrix[3][1] = 3
        Matrix[3][2] = 8
        Matrix[3][3] = 10
        Matrix[3][4] = 5
        Matrix[3][5] = 9
        
        Matrix[4][0] = 2
        Matrix[4][1] = 4
        Matrix[4][2] = 8
        Matrix[4][3] = 11
        Matrix[4][4] = 7
        Matrix[4][5] = 12
        
        Matrix[5][0] = 3
        Matrix[5][1] = 4
        Matrix[5][2] = 5
        Matrix[5][3] = 6
        Matrix[5][4] = 11
        Matrix[5][5] = 10
        
        #These section Loads into trial handler
        print('Created trials')
        trialsList = []
            
            
        for trial in range(6):
            thisTrial = {}
            order = range(6)
            random.shuffle(order)
            for i in range(6):
                
                id = Matrix[trial][order[i]]
                
            if(id ==1):
                image = 'Face.1.jpg'
            elif(id == 2):
                image = 'Face.2.jpg'
            elif(id == 3):
                image = 'Face.3.jpg'
            elif(id == 4):
                image = 'Face.4.jpg'
            elif(id == 5):
                image = 'Face.5.jpg'
            elif(id == 6):
                image = 'Face.6.jpg'
            elif(id == 7):
                image = 'Face.7.jpg'
            elif(id == 8):
                image = 'Face.8.jpg'
            elif(id == 9):
                image = 'Face.9.jpg'
            elif(id == 10):
                image = 'Face.10.jpg'
            elif(id == 11):
                image = 'Face.11.jpg'
            elif(id == 12):
                image = 'Face.12.jpg'
            else:
                image = id
                
            thisTrial[i] = image
        trialsList.append(thisTrial)
        print('SavedTrials')
        
        #This section creates the objects we need for the experiment
        
        img1 = visual.ImageStim(win, size=[5, 5])
        
        
        Target = visual.ImageStim(win, size=[5, 5])
        
        responseClock = core.Clock()
        
        #This is a deceptive block
        trials = data.TrialHandler(trialList=trialsList, nReps=1,
        method='random', 
        extraInfo=expInfo, name='trials')
        thisExp.addLoop(trials)
        
        message4 = visual.TextStim(win, text = "Truthful")
        message4.draw()
        win.update()
        core.wait(2)
        
        for trial in trials:
            fixation.draw()
            win.flip()
            core.wait(1)
            for i in range(6):
                # Prepare stimulus
                #fixation.draw()
                # Show it 
                Target.pos = positions[i]
                Target.image = trial[i]
                Target.draw()
                
            win.flip()
            responseClock.reset()
            boop = 0
            while boop == 0:
                resp = event.waitKeys()
                if resp == ["escape"]:
                    core.quit()
                if resp == ["p"]:
                    boop = 1
                if resp == ["q"]:
                    boop = 1
            
            trials.addData('respDetect.keys', resp)
            trials.addData('respDetect.rt', responseClock.getTime())
            trials.addData('Trial Type', 'Truthful')
            win.flip()
                
            thisExp.nextEntry()

Any help would be welcomed! :slight_smile:

Nathan

Hi Nathan,

I am not really understanding your code completely, and it seems to me that you are not quite using the strengths of python. If I understand correctly what you are aiming for, I would think that the problem is rather easily solved using lists, and then iterating directly over the items of the list. So for your first trial, the list is firstTrial = [“face0”, “face1”, “face2”, “face3”, “face4”, “face5”]. You can randomize the order within the list by using random.shuffle(firstTrial). Within your trial, you can loop over the items of the list directly to set their positions and draw them, i.e.
for pic in firstTrial:
…pic.draw() # or whatever

Hope this helps,
Gernot