Howdy, Stranger!

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

Supported by

Clicking experiment, little issue with a time max response...

edited January 1 in PyGaze

(Sorry it's a bit unreadable but I couldn't code quoting the whole..)

Hi,

So that's the first experience that I try to create, I decided to use OpenSesame but I get some issues, if you have any idea about how to fix it that would be really great. I think I need to say it's the first time I use python so may be the error is really easy to solve but I could not do anything without any experience and I didn't found helpful answers in same issues on internet..

The experiment consists in making one cross appears -click on it when it becomes green-, then a fix dot appears -click on it-, and a last one appears -click on it again-, positions of these events are variables.
And I would want an error message when the subject's click is misplaced or when he doesn't click fast enough, the first one is easy but I'm not able to elaborate the second..

The first try is with this code:

def go():

    first = True
    second = False
    third = False
    ok = False
    rt = clock.time()

    while first:
        my_canvas.image(red_cross, x=var.depart, y=0)
        my_mouse.show_cursor(show=True)
        my_canvas.show()
        clock.sleep(2000)
        my_canvas.image(green_cross, x=var.depart, y=0)
        my_canvas.show()
        button, position, timestamp = my_mouse.get_click(timeout=2000, visible=True)
        x, y = position
        if x < var.depart-erreur or x > var.depart+erreur and y < 0-erreur or y > 0+erreur:
            my_canvas.clear()
            my_canvas.image(precis)
            my_canvas.show()
            clock.sleep(1000)
            my_canvas.clear()
            break
        if x > var.depart-erreur and x < var.depart+erreur and y > 0-erreur and y < 0+erreur:
            global rt1
            rt1 = clock.time() - rt
            my_canvas.clear()
            first = False
            second = True
        else:
            my_canvas.clear()
            my_canvas.image(rapide)
            my_canvas.show()
            clock.sleep(2000)
            my_canvas.clear()
            break


    while second:
        my_canvas.fixdot(x=0, y=var.hauteur)
        my_canvas.show()
        button, position, timestamp = my_mouse.get_click(timeout=2000, visible=True)
        x, y = position
        if x < 0-erreur or x > 0+erreur and y < var.hauteur-erreur or y > var.hauteur+erreur:
            my_canvas.clear()
            my_canvas.image(precis)
            my_canvas.show()
            clock.sleep(1000)
            my_canvas.clear()
            break
        if x > 0-erreur and x < 0+erreur and y > var.hauteur-erreur and y < var.hauteur+erreur:
            global rt2
            rt2 = clock.timme() - rt1
            my_canvas.fixdot(color="yellow", x=0, y=var.hauteur)
            my_canvas.show()
            clock.sleep(50)
            my_canvas.clear()
            second = False
            third = True
        else:
            my_canvas.clear()
            my_canvas.image(rapide)
            my_canvas.show()
            clock.sleep(2000)
            my_canvas.clear()
            break

    while third:
        my_canvas.fixdot(x=var.sens, y=var.hauteur)
        my_canvas.show()
        button, position, timestamp = my_mouse.get_click(timeout=2000, visible=True)
        x, y = position
        if x < var.sens-erreur or x > var.sens+erreur and y < var.hauteur-erreur or y > var.hauteur+erreur:
            my_canvas.clear()
            my_canvas.image(precis)
            my_canvas.show()
            clock.sleep(1000)
            my_canvas.clear()
            break
        if x > var.sens-erreur and x < var.sens+erreur and y > var.hauteur-erreur and y < var.hauteur+erreur:
            global rt3
            rt3 = clock.time() - rt2
            global ok
            ok = True
            my_canvas.fixdot(color="yellow", x=var.sens, y=var.hauteur)
            my_canvas.show()
            clock.sleep(50)
            my_canvas.clear()
            my_canvas.image(white_screen)
            my_canvas.show()
            clock.sleep(1000)
            my_canvas.clear()
            third = False
        else:
            my_canvas.clear()
            my_canvas.image(rapide)
            my_canvas.show()
            clock.sleep(2000)
            my_canvas.clear()
            break

while 1:
    go()
    if ok:
        break

With this one the error is in the 'else', when I wait for two seconds to click on the cross or on the fixdot, pygame crashes and the ErrorType message is "'NoneType' object is not iterable ".. I tried to write it in other ways (like "if button == None:") but with that type of construction the problem keep appearing.

So I tried an other type of construction and I get an another issue..

ok1 = False
ok2 = False
ok3 = False
ok = False

def first():
    my_canvas.image(red_cross, x=var.depart, y=0)
    my_mouse.show_cursor(show=True)
    my_canvas.show()
    clock.sleep(2000)
    my_canvas.image(green_cross, x=var.depart, y=0)
    my_canvas.show()
    t0 = clock.time()
    t1 = t0 + sample_rate
    while 1:
        position, timestamp = my_mouse.get_pos()
        if my_mouse.get_pressed()[0]:
            x, y = position
            if x < var.depart-erreur or x > var.depart+erreur and y < 0-erreur or y > 0+erreur:
                my_canvas.clear()
                my_canvas.image(precis)
                my_canvas.show()
                clock.sleep(1000)
                my_canvas.clear()
                break
            if x > var.depart-erreur and x < var.depart+erreur and y > 0-erreur and y < 0+erreur:
                rt1 = clock.time()
                my_canvas.clear()
                global ok1
                ok1 = True
                break
        if timestamp > t1:
            t1 += sample_rate
            t = timestamp - t0
            if t > response_max:
                my_canvas.clear()
                my_canvas.image(rapide)
                my_canvas.show()
                clock.sleep(1000)
                my_canvas.clear()
                break

def second():
    my_canvas.fixdot(x=0, y=var.hauteur)
    my_canvas.show()
    t0 = start = clock.time()
    t1 = t0 + sample_rate
    while 1:
        position, timestamp = my_mouse.get_pos()
        if my_mouse.get_pressed()[0]:
            x, y = position
            if x < 0-erreur or x > 0+erreur and y < var.hauteur-erreur or y > var.hauteur+erreur:
                my_canvas.clear()
                my_canvas.image(precis)
                my_canvas.show()
                clock.sleep(1000)
                my_canvas.clear()
                global ok1
                ok1 = False
                break
            if x > 0-erreur and x < 0+erreur and y > var.hauteur-erreur and y < var.hauteur+erreur:
                rt2 = clock.time()
                my_canvas.fixdot(color="yellow", x=0, y=var.hauteur)
                my_canvas.show()
                clock.sleep(50)
                my_canvas.clear()
                global ok2
                ok2 = True
                break
        if timestamp > t1:
            t1 += sample_rate
            t = timestamp - start
            if t > response_max:
                my_canvas.clear()
                my_canvas.image(rapide)
                my_canvas.show()
                clock.sleep(1000)
                my_canvas.clear()
                global ok1
                ok1 = False
                break

def third():
    my_canvas.fixdot(x=var.sens, y=var.hauteur)
    my_canvas.show()
    t0 = start = clock.time()
    t1 = t0 + sample_rate
    while 1:
        position, timestamp = my_mouse.get_pos()
        if my_mouse.get_pressed()[0]:
            x, y = position
            if x < var.sens-erreur or x > var.sens+erreur and y < var.hauteur-erreur or y > var.hauteur+erreur:
                my_canvas.clear()
                my_canvas.image(precis)
                my_canvas.show()
                clock.sleep(1000)
                my_canvas.clear()
                break
                global ok2
                ok2 = False
            if x > var.sens-erreur and x < var.sens+erreur and y > var.hauteur-erreur and y < var.hauteur+erreur:
                rt3 = clock.time()
                my_canvas.fixdot(color="yellow", x=var.sens, y=var.hauteur)
                my_canvas.show()
                clock.sleep(50)
                my_canvas.clear()
                my_canvas.image(white_screen)
                my_canvas.show()
                clock.sleep(1000)
                my_canvas.clear()
                global ok
                ok = True
        if timestamp > t1:
            t1 += sample_rate
            t = timestamp - start
            if t > response_max:
                my_canvas.clear()
                my_canvas.image(rapide)
                my_canvas.show()
                clock.sleep(1000)
                my_canvas.clear()
                global ok2
                ok2 = False
                break

def go():
    first()
    if ok1:
        second()
        if ok2:
            third()

while 1:
    go()
    if ok:
        break

The code is may be more complex for what it is but it's cause I tried many options, without any working.. So here the time max is not a problem but the thing is that the first click activates the command on the 'def second' so when the first fix dot appears after the click on the green cross, it automatically make like the subject hadn't clicked on the fixdot and then error of misclicking.

I hope I'm clear and that may be one of you has a simple idea to get it solved ?

Many thanks,
Nicolas

Comments

  • Hi Nicolas,

    Sorry, but this is really a lot of code that seems to make sense somewhat. However, without having a better description of the desired behaviour it is very difficult to help you debugging. Would you mind elaborating a little more? Maybe you could also upload the experiment, so I could have a look?

    Thanks,
    Eduard

  • edited January 2

    Actually to just present clearly my problem, trying to allow mouse clicking detection, I used that function:

    And just using these four lines, the "'NoneType' object is not iterable" error appears..

  • Are you sure you used the example as above? The following typo in line 3 would result in the error you mention:

    if button in None:

    Here, in should have been is.

    If you did copy it without error, then try the following instead of line 2:

    button, pos, timestamp = my_mouse.get_click(timeout=5000)

Sign In or Register to comment.