| Reference | Downloads | Github

Repeating the trial if 'space' is clicked and ending trial after one of the key presses


Dear all

I have been using psychopy builder, 1.83.0 for my experiment. The stimuli presentation and recording is simple. A sound file is played and participant has to select one of the two images on the screen, by pressing ‘left’ of the ‘right’ which ends the trial. This part may have been easy, but I want the trial to be repeated again if ‘space’ bar is pressed.
So, I have set it up such that allowed keys are ‘left’, ‘right’, ‘space’ and added a code component like this

I get the following error

Is there a simple way around this problem?



Looks like you neglected to add camelCase to the function (to my eyes anyway, my sight isn’t what it used to be.
Is it definitely


in all cases and not:



Hi Oli

Thanks for that. Yes! you are spot on. I changed that. And it now seems to not give error.
The problem now is,
It plays the audio and freezes. It does not take responses and end the trial. Nor does it replay the audio if I press ‘space’.

As I explained I want the program to end the trial if either ‘left’ or ‘right’ was pressed. And, replay the stimuli if ‘space’ was pressed.

Aconditions.xlsx (8.6 KB)

Thanks in advance



Hi all

I have made some progress but needs some help in this

As explained above my experiment is very simple, a sound is presented and participant has to press either ‘left’ or ‘right’ key to respond, which ends the trial. In case if the participant want to re-hear the sound, he should press ‘space’, I have set up an inner loop ‘trials_5’, with empty conditions of 999 reps, so it can repeat the sound gets repeated if ‘space’ is pressed.

put something loike this in my Begin Expeirment component of the code

key_resp_3 = event.getKeys(keyList=[‘space’, ‘left’,‘right’])
isCollecting = True

#And in the each frame
if key_resp_3.keys == ‘space’:
continueRoutine = False # trial will run again
thisExp.addData(‘reps’, ‘1’)
else :
thisExp.addData(‘reps’, ‘0’)

if key_resp_3.keys==eval(CorrAns):
     thisExp.addData('score', 1)
     score = score + 1
     thisExp.addData('wrongAnswer', 1)
     wrongAnswer= wrongAnswer+ 1
     continueRoutine = False 
     trials_5.finished = True
if wrongAnswer==3:

When I had excluded the code after first six lines that does the repetition part, it works fine. That is, it repeats the same trial, if I press ‘space’.

When I included the whole code as above, it just plays all the trials one after another without waiting to take my response.

Can any body help?


The program was repeating if I press the space bar. However, when the