Howdy, Stranger!

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

Supported by

Help with "while False:" loop

Disclaimer: Whilst my experiment implements PyGaze functions, I felt that this was more of an OpenSesame issue. Hence, I posted my question in the OpenSesame sub-forum.

Background: I am programming a gaze-contingent eye-tracking design, starting with a fixation dot. Originally this is a sketchpad, but for the current status I found it easier to use the canvas functions. I have some Python experience (I created an ssVEP/EEG experiment with PsychoPy) and used the for-loop in Matlab/PsychToolbox, but the while-loop is reasonably new to me.

What I want it to do: A fixation dot is presented, and an area of interest is drawn around it, let's call this fixation-area. If the participant does not fixate the fixation-area, nothing will happen until it times out. Once the gaze is directed at the fixation-area, a timer will start. After 500 ms the next screen will be presented.

Please note that the following coordinates are not final: I currently present the experiment in a small window to keep an eye on the debug-window. And I noticed that PyGaze does not use uniform coordinates, so I unticked this. The fixation dot and AOI on this screen are in the centre.

Prepare phase:


# Set up constants. Note that I am drawing a visual representation of my AOI. Coordinates are not final. 

my_canvas = canvas()
my_canvas.fixdot()
my_canvas.circle(350, 195, 100, fill=False, color='red')

# Set the Area around the fixtion dot (type, pos, size)
FixAOI = AOI('circle', (350,195), 100)
FixDuration = 495
timeout = 10000

Run phase:



# Show the screen. Eventually I want to use sketchpad items instead of canvases.
my_canvas.show()

# Get the current time and print this for debugging purposes.
t0 = self.time()
print('T0 %f' % t0)

# Get and print the x,y tuple of the gaze position. Start the timer.
GazePos = eyetracker.sample()
print('GazePos = ', GazePos)
var.current_time = self.time() - t0

# As long as the gaze position is not within the AOI, wait until it is or time out. This calls on the imported AOI plugin. Sleep command set for now to avoid drowning the debug window 
while False:
    FixAOI.contains(GazePos)
    var.current_time = self.time() - t0
    if var.current_time < timeout:
        print('Duration if not hit =', var.current_time)
        clock.sleep(50)
    elif var.current_time >= timeout:
        print('timed out')
        break
    else:
        print('FML')
        break

# When the gaze position IS within the AOI, count the timer until the given fixatio duration is reached.    
while True:
    FixAOI.contains(GazePos)
    var.current_time = self.time() - t0
    if var.current_time < FixDuration:
        #t1 >= FixDuration
        print(u'T1 during hit', var.current_time)
        clock.sleep(10)
    elif var.current_time >= FixDuration:
        print('Fixated!')
        break
    else:
        print('hit but FML')
        break

What it does: it skips the False part altogether, even though GazePos is printed as outside of the fixation-area. The timer seems to work okay and OpenSesame succesfully presents the next screen, but it appears to just see FixAOI.contains(GazePos) as True.

It is probably just a rookie error in creating the loop. Any help would be greatly appreciated!

Comments

  • Hi,

    You're misunderstanding the semantics of a while loop!

    This:

    while True:
        something()
    

    Means: enter an infinite loop that runs something() over and over again. It does not mean: run the loop while something() is True.

    Analogously, this:

    while False:
        something()
    

    Means: never enter the loop (because the criterion is already False on the first iteration)—in other words, it does nothing. It does not mean: run the loop while something() is False. This does:

    while not something():
        pass
    

    However, I think it's best to take a step back and familiarize yourself with basic Python syntax. That won't take long, and will avoid you from getting stuck every step of the way.

    Cheers!
    Sebastiaan

  • Thanks @sebastiaan, that really cleared things up! I made it work with the following script. It needs some tweaking as it is ugly, but moreover, even with the clock.sleep() function the execution seems to carry on after the onset of the next screen (although maybe that was just when I printed debugging data, but I don't want to chance it).

    
    my_canvas.show()
    
    # As long as the gaze position is not within the AOI, wait until it is or time out. This calls on the imported AOI plugin. Sleep command set for now to avoid drowning the debug window 
    
    # Start by declaring that the AOI is not fixated (HitAOI) for enough time (is_fixation)
    HitAOI = False
    is_fixation = False
    
    # So it enters this loop, which keeps updating the Gaze position and starts the timer, but resets it if gaze is averted from AOI.
    while HitAOI is False or is_fixation is False: 
        GazePos = eyetracker.sample()
        print('GazePos = ', GazePos)
        t0 = clock.time()
        HitAOI = False
        clock.sleep(5)
        # While a sample is detected in the AOI but not for 495 ms yet, start counting until 495:   
        while FixAOI.contains(GazePos) and is_fixation is False:
            HitAOI = True
            GazePos = eyetracker.sample()
            t1 = clock.time() - t0
            clock.sleep(5)
            # Gaze sample within AOI for 495 ms, exit the loop and move on! 
            if t1 >= FixDuration:
                is_fixation = True
                clock.sleep(5)
            # But any less than 495 ms, keep counting
            else:
                is_fixation = False
                clock.sleep(5)
    

    Wonderful, thanks again!

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