[open] Canvas timeout with no mouse response
Hi there,
I am working on an experiment where I would like to collect participants' responses using the mouse. Specifically, I have defined two possible responses as areas on the screen. If a participant clicks outside these possible areas, I would like that canvas to continue displaying to the screen. Also, I would like the experiment to progress if no response is made for 7 seconds. Here's the code I am trying to use:
my_mouse = mouse(exp)
my_mouse.set_visible()
my_mouse.set_timeout(timeout=None)
my_mouse.set_pos(pos=(x_half,y_half))
while True:
button, position, timestamp = my_mouse.get_click(timeout = 7000)
if ((x_eighth) < position[0] < (x_eighth*3)) and ((y_quarter) < position[1] < (y_quarter*3)): #defining area 1
disc_response = 'L'
break
elif ((x_eighth*5) < position[0] < (x_eighth*7)) and ((y_quarter) < position[1] < (y_quarter*3)): #defining area 2
disc_response = 'R'
break
my_canvas_inter.clear()
my_canvas_inter.show()
disc_response = 'na' #if no response
When I run this, I get the following error "TypeError: 'NoneType' object has no attribute 'getitem'" for the line with the first if statement. This error occurs after the 7 second timeout is up, but instead of progressing, the experiment ends. However, if I select one of the relevant areas during the experiment, it runs without a hitch. Any insight on this problem would be greatly appreciated.
thank you!
Allison
Comments
Hi Allison,
The error occurs because
position
isNone
when a timeout occurs. Therefore, you will get an error if you try something likeposition[0]
after a timeout, even though this works fine after a response has been given, in which caseposition
will be an (x,y) tuple. So you will need to explicitly check whetherposition
isNone
, and (in your case) break the loop when this happens.See also:
However, I don't think you even need a loop in your case, because you check only once for a button press, and then move on. Right? So something like the following structure should do equally well:
And finally, don't forget to set the variable
disc_response
at the end of the script, so it can be logged and will be available elsewhere in the experiment:See also:
Hope this helps!
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thanks for the feedback, Sebastiaan. Here's the code that did the job:
Now that I have that figured out, I have another question. I had added a form_multiple_choice item to my experiment. However, the information (i.e., the form title, response variable, button text, question, and response options) in this item is being inexplicably deleted each time I try and open the same saved file. This happens on the same computer I used to save the experiment in the first place. I am using the most recent version of OpenSesame on a Dell running Windows 7. Any insight, or is this just a glitch?
Thanks!
Allison
This is indeed a known bug (issue). It has been fixed in the development release, so you could try the latest development snapshot of 2.8.0.
Alternatively, if you prefer to stick to the stable release, you could download the latest source code from GitHub and replace only the
plugins/form_multiple_choice
folder in your current installation of OpenSesame.Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!