psychopy.org | Reference | Downloads | Github

Ending routine and skipping not working

Helllo all! Thank you again for all your help with my previous question. I’ve been learning a lot from you, but am currently rather stumped.

OS : Windows 10
PsychoPy version : 3.2.4
Standard Standalone? (y/n) : Yes

Context: After showing an English words with four translation options and displaying and storing feedback for later routines (Correct/Incorrect), I am trying to skip the incorrectMeaningFeedback routine when feedback = ‘Correct’, and run it when feedback =‘Incorrect’. In case of running the routine, you should be able to press ‘t’ to display the correct translation text (setting color from black to white to make it visible). It should only show while keeping ‘t’ pressed; repeated presses should be allowed and press duration cumulatively recorded (didn’t get to that part yet), spacebar should end the routine and continue with the next trial in the outer loop.

The problem:
A. Routine does not end when feedback = ‘Correct’, instead infinitely displaying the background.
B. Pressing space or t does not end routine or show translation respectively

What I have tried to do is debug with print(), see code below. I have concluded the keys are being registered, but there is something wrong with executing the statements aside from print(). In summary:

Problem A. When the feedback == ‘Correct’:
It prints the ‘End at begin routine correct’ but continues to print the ‘No escape, no t, no space’ until I press escape. I have tried this if feedback == ‘Correct’: both at begin and end or routine.

Problem B. When the feedback == ‘Incorrect’:
It again prints only the associated text in the output when pressing either ‘space’ or ‘t’ or continues to print the ‘No escape, no t, no space’ until I press escape

I have no idea what I am doing wrong here. Any and all help is very welcome, thank you in advance for your response and time!

The current code in the code_iMF

Begin Routine:

if feedback == 'Correct':
    trials_feedbackLoop.finished = True 
    continueRoutine = False
    meaningFeedback = "" #temporarily added as this gave error if not set
    translationFeedback = "" #temporarily added as this gave error if not set
    print('End at begin routine correct') #Prints statement, does not end
elif feedback == 'Incorrect':
    meaningFeedback = 'Keep the letter t pressed to see the right translation: \n\n\n' + str(currentWord) + '\n\n\n Press <SpaceBar> to continue'
    translationFeedback = correctAnswer
    print('Running incorrect loop')

Each Frame:

keys = event.getKeys()

if keys:
    if 'escape' in keys:
        core.quit()
    elif 'space' in keys: #must include something that checks whether mouse has been pressed
        trials_feedbackLoop.finished = True 
        text_iMF_Translation.setColor([-1.000,-1.000,-1.000],'rgb')
        print('Spacebar pressed, ending routine')
    elif 't' in keys:
        text_iMF_Translation.setColor([1.000,1.000,1.000],'rgb')
        print('t key pressed, color for feedback white')
else:
    text_iMF_Translation.setColor([-1.000,-1.000,-1.000],'rgb')
    print('No escape, no t, no space')

End Routine:

if feedback == 'Correct':
    trials_feedbackLoop.finished = True 
    print('End at end routine correct')
1 Like

Update!

Hi guys, I had some inspiration and managed to make most of it work, though it might not be the most elegant solution ever.

The reason it wasn’t ‘working’ in spite of registering the buttons was because I had put the color to ‘Set every frame’ in the object setting… so that was causing a bit of a conflict.

Current solution should anyone need to do something similar:

Begin Routine:

if feedback == 'Incorrect':
    meaningFeedback = 'Keep left mouse button pressed in cross to see the right translation: \n\n\n' + str(currentWord) + '\n\n\n Press <SpaceBar> to continue'
    translationFeedback = correctAnswer

else:
    meaningFeedback = ""
    translationFeedback = ""

Each Frame:

#IMPORTANT - time of mouse button pressed is not being saved currently!

if feedback == 'Correct':
    continueRoutine = False
    #iMF_keys = ['space']
else:
    iMF_keys = key_resp_iMF.keys
    mouse_state = mouse_iMF.isPressedIn(shape = target_polygon_iMF, buttons = [0])
    if mouse_state == True:
        text_iMF_Translation.setColor([1,1,1],'rgb')
    elif iMF_keys:
        print('Currentkey: ' +str(iMF_keys))
        #must include something that checks whether mouse has been pressed ? or allow 0 effort?
        continueRoutine = False
    elif mouse_state == False:
        text_iMF_Translation.setColor([-1,-1,-1],'rgb')