Multiple randomised images to click at each frame

OS (e.g. Win10): Win 10
PsychoPy version (e.g. 1.84.x): 3.2.4

During my psycholinguistic experiment, the participants need to learn sound-letter relations by themselves. After the training phase, they conduct a mini-test as follows:

  1. The multiple letter images are displayed in random order.

  2. When a phoneme is heard, the participants need to click the corresponding letter.

  3. If the total number of the correct answers is below 90%, they repeat the training.

=================================================

Begin Routine

if MiniTest_loop.thisN == 0:
   number_correct = 0

*Each Frame*
for stimulus in [image1, image2, image3, image4]:    
   if Mini_Response.isPressedIn(stimulus):
        thisExp.addData('RT',t)
        thisExp.addData('choice', stimulus.image)            
        if stimulus.image == eval(Correct_mini): 
            thisExp.addData('correct', 'True')
            number_correct += 1 *** sometimes adds rediculous number, like 1 to 8
        else:
             thisExp.addData('correct', 'False')

*End Routine*
if Mini_Response.clicked_name[0]==Correct_mini:
    number_correct += 1 *** likewise, also never prints!
    print("Score:")
    print(number_correct)

if MiniTest_loop.thisN + 1 == MiniTest_loop.nTotal:
    if number_correct/(MiniTest_loop.nTotal + 1) >= 0.90:
        NoPass.finished = True
        print('Passed!')
    else:
        again_text.setText(u'Back to training', log=False)
        again_text.opacity=1
        again_text.draw()
        win.flip()
        core.wait(2.0)
        NoPass.finished = False
        
print("Turn:")
print(MiniTest_loop.thisN)
print("Image:")
print(stimulus.image)

=====================================================
** My apologies for omitting the front spaces.

The problems are:

  1. It prints the wrong image file name: for example, when I click n.png, it prints l.png (most of the time, it print l.png). BUT, the csv data correctly record the clicked images.

  2. I can’t get out of the loop NoPass until the number I setup (nReps in NoPass loop). Related to the above, I guess it might be because the wrong image file is recognized, so the calculation becomes totally wrong. This is a more serious problem.

  3. When the RealTest starts, the text ‘back to training’ keeps appearing. I’d like to remove this.

I would appreciate it very much if anyone leaves a helpful comment. Thank you in advance!

We really do need to see those, to know if the code logic is correct:

Aha! Didn’t know where to put those backticks. Thanks, Michael!

Hi, again!

I think I solved the issue and would like to share just in case someone else is struggling for the same.

The biggest problem of the above code was that I couldn’t track whether the clicked image was correct or not because I designated the images to the variables constantly changing. Instead, I designated the locations as the variables changeable as below. See that images have the concrete names now and changeable positions.

*Begin Routine*
if MiniTest_loop.thisN == 0:
    number_correct = 0
    
shuffle(poslist)

*End Routine*
if Mini_Response.clicked_name[0]==Target_mini:
    number_correct += 1
    thisExp.addData('correct','TRUE')
else:
    thisExp.addData('correct','FALSE')
    

if MiniTest_loop.thisN + 1 == MiniTest_loop.nTotal:
    if number_correct/(MiniTest_loop.nTotal + 1) >= 0.70:
        NoPass.finished = True

    else: 
        if NoPass.thisN == 1:
            NoPass.finished = True
        else:
            again_text.setText(u'Back to training', log=False)
            again_text.opacity=1
            again_text.draw()
            win.flip()
            core.wait(2.0)
            NoPass.finished = False

If you have any questions or comments, please leave it here. Thanks!

1 Like