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

    Buy Me A Coffee

  • edited January 2018

    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.

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