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 8:34AM

    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 8:34AM

    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 8:34AM

    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.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games