OS (e.g. Win10): MacOS Mojave
PsychoPy version (e.g. 1.84.x): v3.1.2
Standard Standalone? (y/n) Yes
What are you trying to achieve?:
I want to conditionally run routines based on keyboard responses given.
In this task, I have a fixation routine, trial routine and break screen routine. The fixation should stay on the screen until a button is pressed. If “s” is pressed, it should go to the trial routine, if 'b" is pressed it should go to the break screen routine and if “t” is pressed it should terminate the loop.
In the trial routine, if “b” is pressed it should go to the break screen, if “t” is pressed then it should terminate the loop but if nothing is pressed then it should skip the break screen routine and restart the loop.
What did you try to make it work?:
Currently, I can successfully get the trial routine to run in response to pressing ‘s’ during the fixation routine. In a code component, under the Begin Routine tab on the trial routine, I’ve successfully used this:
#display the trial if 's' was pressed during fixation
#i.e., if any key that wasn't 's' was pressed
#then don't run the "trial" routine and move onto the next routine
# keyboardPress is the keyboard component during fixation
if keyboardPress.keys != 's' :
continueRoutine = False
And I can use ‘t’ to terminate the loop on all routines. On each routine I have a code component that looks like this under the Each Frame tab, uses this:
#End the block 'trials' if 't' is pressed
if keyboardResponseTrial.keys == 't':
trials.finished=True
But I can’t get the breakscreen to display if ‘b’ is pressed during fixation or the trial routines. Here’s the code component I’ve used on the breakscreen routine, under the Begin Routine tab, that isn’t working (I’m not getting an error, it’s just not happening).
#display the breakscreen if b is pressed
#i.e., if any key that isn't 'b' is pressed
#then don't run the "breakScreen" routine
# keyboardPress is the keyboard component during fixation
# keyboardResponseTrial is the keyboard component during trial
if keyboardPress.keys != 'b' or keyboardResponseTrial.keys != 'b':
continueRoutine=False
Any guidance or advice as to why this breakscreen routine won’t conditionally display when the correct key is pressed on prior routines would be greatly appreciated!