Redo all incorrect trials

Hi all,

I figured out what I posted above earlier. In case anyone asks the same questions, I’m posting the code I used to solve this.

Have a good day,

Noah

ImagesToRedo = 1
TestIteration = 0
IncorrectAnswers = data.importConditions('image+soundFiles.xlsx') #TestPhaseFilename + str(TestIteration).zfill(2) + '.xlsx'
CorrectMsg = visual.TextStim(win = win, units = 'norm', height = 0.1,
            pos = (0,0), text = "Correct!", alignHoriz = 'center',
            alignVert = 'center', color = [0, 0, 0], wrapWidth=1)

while ImagesToRedo:
    # Set the excel sheet to use for this trial
    TestIteration = TestIteration + 1
    # set up handler to look after randomisation of conditions etc
    TestingPhase = data.TrialHandler(nReps=1, method='random',
        extraInfo=expInfo, originPath=-1,
        trialList= IncorrectAnswers,
        seed=None, name='TestingPhase')
    ThisLoopFileName = ""
    # Set variables to be used in the testing phase
    thisExp.addLoop(TestingPhase)  # add the loop to the experiment
    IncorrectAnswers = []

    # Start the loop of TestingPhase
    for testImgii in TestingPhase:
        currentLoop = testImgii
        # Set some basics

        ContinueStim = True

        while ContinueStim:
        # Draw the object to screen

            if finalAnswerGiven and CORRECT:
                # Correct answer!!
                CorrectMsg.setAutoDraw(True)
                print("Hooray")
                CorrectOrMiss = 1
            elif finalAnswerGiven and not CORRECT:
                # Incorrect answer produces correct position and sound
                # Append the list of stims for next test loop
                IncorrectAnswers.append({'ImageN' : ImageN, 'SoundID' : SoundID, 'cx' : cx, 'cy' : cy})
                #IncorrectAnswers.append(dict(TestingPhase.trialList[TestingPhase.thisIndex]))
                print("Need to do again:")
                print(IncorrectAnswers)
                CorrectOrMiss = 0

            if finalAnswerGiven:
                TestingPhase.addData('ImgTimeSpent', t)
                TestingPhase.addData('PositionAnswer', finalAnswer)
                # For the output below, set the distance to cm
                #TestingPhase.addData('DistanceFromBingo', )
                TestingPhase.addData('TimeImgPressed', pressTimeClock.getTime())
                TestingPhase.addData('HitOrMoss', CorrectOrMiss)
                # DragImage.setOpacity(0)
            # Stop loop if 'esc' key is pressed
            if event.getKeys(keyList=["escape"]):
                core.quit()

            if ContinueStim:
                win.flip()

        routineTimer.reset()
    ImagesToRedo = len(IncorrectAnswers)
    if bool(ImagesToRedo):
        NextMsg = 'There are still ' + str(ImagesToRedo) + ' images to correctly place'
    else:
        NextMsg = 'Congragulations! You got them all right! You''re done! Left-Click to exit'

2 Likes