I have a psychopy builder task and I would like to send a trigger for correct and incorrect responses based on the key_resp.corr variable.
What I’ve done:
I have added a code component in the specific routine and put the code to send the trigger. Because there is another trigger straight after the key press i have introduced a short pause after the trigger is sent so that both the key press trigger sends and the fixation cross following it sends. The code below works using key_resp.keys (either left or right) meaning the code works and sends the trigger but not with the key_resp.corr variable.
Please let me know if you know what might be the issue.
I have used key_resp.corr in previous code to skip routines therefore Its strange it doesnt work here.
Begin experiment: from psychopy import event, core
if key_resp_10.corr == 1 and not stimulus_pulse_corr_started:
win.callOnFlip(port.write,[22])#Send the trigger, synced to the screen refresh
stimulus_pulse_corr_start_time = globalClock.getTime()
stimulus_pulse_corr_started = True
if stimulus_pulse_corr_started and not stimulus_pulse_corr_ended:
if globalClock.getTime() - stimulus_pulse_corr_start_time >= 0.005:
win.callOnFlip(send_triggers, [0])
stimulus_pulse_corr_ended = True
if stimulus_pulse_corr_started and stimulus_pulse_corr_ended and not pause_corr_ended:
core.wait(0.01)
pause_corr_ended = True
if pause_corr_ended:
continueRoutine = False
When you run the experiment, make sure you delete the print command. From your post, I gathered that the if-statement involving key_resp10.corr is not being evaluated. I therefore suggested checking the values of the relevant variables. Have I understood you correctly?
I guess that you could simplify your code to
if key_resp_10.corr:
win.callOnFlip(port.write,[22])#Send the trigger, synced to the screen refresh
core.wait(0.005) # this is really short
win.callOnFlip(send_triggers, [0])
core.wait(0.01)
continueRoutine = False
I am not sure how “well” the Builder copes with the addition core.wait and win.callOnFlip.
Commands following the ‘if’ construction are only executed when the ‘if’ construction evaluates as true. This only occurs when the pressed key corresponds with the correct one. Otherwise, the if-construction evaluates as false and the commands are not executed.
The code you posted does not deal with incorrect answers.
So if we want to it to send a trigger when they press an incorrect response we wouldn’t be able to because key_resp_10.corr is always 0 until its 1 so it will send it before the key press?
The reason we haven’t done key_resp_10.keys is because the location of the words on screen (old and new) swap depending on the trial and therefore correct answer depends on the screen location not on old always being ‘left’ and new always being ‘right’
What is send before the key press? The trigger? No, currently the trigger is only send when the answer is correct. In addition, currently the trial only ends when the correct key is pressed!
I do not understand this. Do you use a column in your condition file to define the correct key? If so, I do not see the problem.
we had a separate code element with if key_resp_10.corr == 0 send a different trigger, and that trigger would send at the beginning of the routine before the key press, which is weird because it has not been defined yet
we do have a column in the condition file, which defines if the correct position is either left or right, but if the correct answer is old and the word old is located on the right side, the correct position is right, but if its located on the left, the correct position is left. Therefore, if we just send a trigger for key press left or right, it doesnt tell us if they got it correct or incorrect. This is why we wanted to use the key_press_10.corr variable instead but it doesn’t seem to behave the same way.
Ok, I begin to understand your experiment. Here is some updated code
if key_resp_10.keys: #a response was given
if key_resp_10.corr: #correct response given
win.callOnFlip(port.write,[22]) #Send the trigger, synced to the screen refresh
core.wait(0.005) # this is really short, half a millisecond
win.callOnFlip(send_triggers, [0])
core.wait(0.01)
continueRoutine = False
else: # incorrect response given
win.callOnFlip(port.write,[??]) #Send the trigger, synced to the screen refresh
core.wait(0.005) # this is really short, half a millisecond
win.callOnFlip(send_triggers, [0])
core.wait(0.01)
continueRoutine = False
So, participants have to indicate the position of the old world, which can either be left or right? Do you use the cursor keys, left and right?
You want to continue to the next trial when a response was given, correct?
OK, instead of sending a trigger, just present different words or symbols for when the response is correct and when it is incorrect. I want to eliminate the possibility of a problem with the trigger.