Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[open] Canvas timeout with no mouse response

edited September 2013 in OpenSesame

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

  • edited 10:22AM

    Hi Allison,

    The error occurs because position is None when a timeout occurs. Therefore, you will get an error if you try something like position[0] after a timeout, even though this works fine after a response has been given, in which case position will be an (x,y) tuple. So you will need to explicitly check whether position is None, and (in your case) break the loop when this happens.

    while True:
        button, position, timestamp = my_mouse.get_click(timeout = 2000)
        if position == None:
            disc_response = 'na'
            break
    

    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:

    button, position, timestamp = my_mouse.get_click(timeout = 2000)
    if position == None:
        disc_response = 'na'
    else:
        # Process the response here
    

    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:

    exp.set('disc_response', disc_response)
    

    See also:

    Hope this helps!

    Cheers,
    Sebastiaan

  • edited 10:22AM

    Thanks for the feedback, Sebastiaan. Here's the code that did the job:

    my_canvas_inter.text('Which one had more dots?', x = x_half, y = y_quarter)
    my_canvas_inter.prepare()
    t = my_canvas_inter.show()
    
    my_mouse = mouse(exp)
    my_mouse.set_visible()
    my_mouse.set_timeout(timeout=5)
    my_mouse.set_pos(pos=(x_half,y_half))
    
    start_time = self.time()
    if my_mouse.flush() == False:
        click = None
    elapsed_time = 0
    while elapsed_time <7000:
        if click == None:
            click, position, timestamp = my_mouse.get_click()
        if click ==1:
            if ((x_eighth) < position[0] < (x_eighth*3)) and ((y_quarter) < position[1] < (y_quarter*3)):
                break
            elif ((x_eighth*5) < position[0] < (x_eighth*7)) and ((y_quarter) < position[1] < (y_quarter*3)):
                break
            else:
                click, position, click_end_time = my_mouse.get_click()
        elapsed_time = self.time() - start_time
    print click, "click"
    if click == None:
        disc_response = 'na'
    if click == 1:
        if ((x_eighth) < position[0] < (x_eighth*3)) and ((y_quarter) < position[1] < (y_quarter*3)):
            disc_response = 'L'
            sel_value = number1
            if number1 > number2:
                trial_acc = 1
            elif number1 < number2:
                trial_acc = 0
            elif number1 == number2:
                trial_acc = 'na'
        elif ((x_eighth*5) < position[0] < (x_eighth*7)) and ((y_quarter) < position[1] < (y_quarter*3)):
            disc_response = 'R'
            sel_value = number2
            if number1 < number2:
                trial_acc = 1
            elif number1 > number2:
                trial_acc = 0
            elif number1 == number2:
                trial_acc = 'na'
    

    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

  • edited 10:22AM

    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 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

Sign In or Register to comment.