I am using psychopy to design an experiment in which participants reach for targets using their mouse. Success is determined by whether the target circle contains the mouse during a specific time window. We have stored a boolean variable which indicates whether the participants succeeded or not. We tried to set that boolean value as the response for a staircase of target size in a code component, but it seems to have no effect and the trial is recorded as incorrect every time.
trials.addResponse(pos_corr)
Going through the code, I found a comment preceding a line:
# NB PsychoPy doesn't handle a 'correct answer' for mouse events so doesn't know how to handle mouse with StairHandler
trials.addData('mouse_6.x', mouse_6.x)
So I suspect that it has been returning false because of this. There is no keyboard component in the experiment.
Is there any way that I can set up the response for the staircase manually? Thanks in advance!
OS (e.g. Win10): Mac Big Sur PsychoPy version (e.g. 1.84.x): 2020.2.8
Hi wakecarter, thanks for the response! I don’t want to add a line to my data file though, I want to set up a variable as the response for my staircase update. Do you have any solutions for that?
Did you ever find a solution to this problem? I want to use the returned value from a rating scale to make up/down (incorrect/correct) decisions to “feed” the staircase algorithm. Currently I’m trying to simulate the subject having pressed ‘left’ or ‘right’ on the basis of a code block - and not having much joy.
My solution:
In the builder, add a custom code component to the top of the trial routine, and put this code in the End Routine tab:
if (currentLoop instanceof MultiStairHandler) {
currentLoop.addResponse(mouse.corr[0], level);
}
I figured it out by noticing these lines of code in my Exp.js file inside function WelcomeRoutineEnd(snapshot):
// update the trial handler
if (currentLoop instanceof MultiStairHandler) {
currentLoop.addResponse(key_resp.corr, level);
}
I think this was added automatically because my Welcome routine had a keyboard response component (just press space to continue) even though it was not inside the staircase loop. This code should be in the RoutineEnd function of any routine that interfaces with the staircase, but it is seems to only be added automatically for keyboard responses. So by adding the custom code component, you can manually add it for the mouse response.
I originally also had a “press space to continue” routine inside the staircase loop (appearing right after each trial), and this caused an error of response must be either 0 or 1, got: undefined because this auto-created code tried to input the spacebar response to the staircase, but spacebar does not correspond to correct or incorrect. To stop this error I had to remove the space response entirely and converted the routine into a simple 0.5 second delay (I think making it “click to continue” should also work)