Howdy, Stranger!

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

Supported by

Simple coroutine question

edited June 2016 in OpenSesame

Hello,

The coroutine function is fantastic, but I'm not able to get the coroutine to end after a button press. Basically I present a stimulus for 500ms, it is replaced by a blank screen for up to 1500ms (before a 2000ms timeout - and this is where the coroutine function came in handy). But I've tried setting the duration of the coroutine to 'keypress' and it doesn't seem to work - am I missing something very obvious?

Thank you!

Comments

  • edited 6:47AM

    Hi,

    That's an interesting question. Right now, coroutines has a fixed duration. But what you could do is define your own generator function in an inline_script that

    1. Checks whether a response has been given; and if so
    2. Changes the coroutines duration to 0, triggering an immediate timeout.

    Like so:

    def break_coroutines():
    
        """A generator that breaks a coroutine when a response is given."""
    
        # To start, set response to None
        var.response = None
        yield
        # Loop while coroutines is running
        while True:
            # If a response is given, set the coroutines duration to 0, causing
            # it to stop
            if var.response is not None:
                items['my_coroutines'].var.duration = 0
                break
            # Also break if the coroutines signals that it's over
            keep_going = yield
            if not keep_going:
                break
    

    You'd then add 'break_coroutines' in the 'Generator function name' field of the coroutines plug-in.

    It's a bit of a hack though ... I'll see if I can think of a more elegant way to do this.

    Cheers,
    Sebastiaan

  • edited 6:47AM

    Hi Sebastiaan,

    Great thank you! I will give it a shot and let you know how it goes.

    Best,
    Mikael

  • edited 6:47AM

    Hi Sebastiaan,

    So I am getting a 'zero division error' - float division by zero. It seems like the loop in the inline script isn't working: if I set items['my_coroutines'].var.duration = 1 then I see subsequent trials for 1ms, so the script is not only applying the 'set coroutines duration to 0' to a single trial, but to every subsequent trial.

  • edited 6:47AM

    Ow right! You need to set duration back to its original value before the coroutines is started. To do so, you can add an inline_script immediately before the coroutines plug-in, with the following code in it (either in the Run or Prepare phase):

    # Replace 5000 by the original duration of the coroutines
    items['my_coroutines'].var.duration = 5000
    
  • edited 6:47AM

    Works great! I placed it in the prepare phase of the main script you passed along - a super useful fix!

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