If this template helps then use it. If not then just delete and start from scratch.
OS (e.g. Win10): Windows 11 pro PsychoPy version (e.g. 1.84.x): 2024.2.3 Standard Standalone? (y/n) Y What are you trying to achieve?:
My feedback for trials works except for code to show text “Faster” if the first mouse press in the trial occurs after the defined stimDuration. Current code is:
if (mouse.time[-1] >stimDuration):
fb_text = 'Faster'
fb_col = 'yellow'
miss = miss+1
cumMiss = cumMiss+1
continueRoutine = False
elif mouse.clicked_name[-1] == corrClick:
fb_text = 'Correct!'
fb_col = 'green'
miss = miss+0
cumMiss=cumMiss+0
# if not practice
if block_num > 0:
# add correct count
c = c+1
correctInBlock = correctInBlock +1
else:
mouse.clicked_name[-1] != corrClick
fb_text = 'Incorrect'
fb_col = 'red'
wrong = wrong+1
cumWrong=cumWrong+1
Tried
I also tried using t based on this, as ‘t’ appears to be a special variable for timing:
I also tried looking length(mouse.clicked_name)
to try to get the elapsed-time-in-trial property.
Fair question, I would like to show the “Faster” text either if stimDuration passes with no mouse press, or if a mouse press occurs any time outside stimDuration (which would mean they clicked so late it went into the interstimulus interval or the fixation). However, the former is far more important than the latter. They probably can tell if they pressed so late that nothing is on the screen, whereas they may not be sure what happened if everything just disappeared and they don’t know what happened.
To that end, it might be useful to add a brief (1 second?) period to the ISI for the “Faster” display. That is probably the ideal.
If the trial is set to end on a mouse click then you could put the following in End Routine
if mouse.clicked_name[-1] == corrClick:
fb_text = 'Correct!'
fb_col = 'green'
miss = miss+0
cumMiss=cumMiss+0
# if not practice
if block_num > 0:
# add correct count
c = c+1
correctInBlock = correctInBlock +1
elif mouse.clicked_name:
fb_text = 'Incorrect'
fb_col = 'red'
wrong = wrong+1
cumWrong=cumWrong+1
else:
fb_text = 'Faster'
fb_col = 'yellow'
miss = miss+1
cumMiss = cumMiss+1
Set the duration of the trial routine to stimDuration and Correct, Incorrect or Faster will show in the feedback routine. It doesn’t matter if the mouse is clicked during that period (or does it?).
I made a small modification to get the Incorrect working again:
> if mouse.clicked_name[-1] == corrClick:
> fb_text = 'Correct!'
> fb_col = 'green'
> miss = miss+0
> cumMiss=cumMiss+0
> # if not practice
> if block_num > 0:
> # add correct count
> c = c+1
> correctInBlock = correctInBlock +1
> elif mouse.clicked_name[-1] != corrClick:
> fb_text = 'Incorrect'
> fb_col = 'red'
> wrong = wrong+1
> cumWrong=cumWrong+1
> else:
> fb_text = 'Faster'
> fb_col = 'yellow'
> miss = miss+1
> cumMiss = cumMiss+1
You mentioned if the “trial is set to end on a mouse click”, which I’m guessing you meant the setting in the flow window. ‘mouse’ and ‘mouse.click’ didn’t work, so I set it to stimDuration thinking that actually might timeout the task and trigger the ‘else’. It just crashes.
If I remove the “flow” “timeout” value, the exist error is:
Traceback (most recent call last):
File “C:\Users[…]\PASAT_pre_lastrun.py”, line 4470, in
run(
File “C:\Users[…]\PASAT_pre_lastrun.py”, line 2264, in run
if mouse.clicked_name[-1] == corrClick:
IndexError: list index out of range
The Correct and Incorrect work, but when I wait and press nothing, that is the crash message.
I then rearranged the order of checking and found “getPressed”, which solved it!
if mouse.getPressed()[0] == 0: # No mouse click
fb_text = 'Faster'
fb_col = 'yellow'
miss += 1
cumMiss += 1
elif mouse.clicked_name[-1] == corrClick:
fb_text = 'Correct!'
fb_col = 'green'
miss += 0
cumMiss += 0
# if not practice
if block_num > 0:
# add correct count
c += 1
correctInBlock += 1
elif mouse.clicked_name[-1] != corrClick:
fb_text = 'Incorrect'
fb_col = 'red'
wrong += 1
cumWrong += 1
I might have not explained the preferred behavior well initially. I hope others might benefit from this solution.
I see, I’ll experiment to see how this performs differently too. That’s why I mentioned I wasn’t sure what “If the trial is set to end on a mouse click” referred to. I did not have this setting, and was thinking you meant in the “flow” setting.