Howdy, Stranger!

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

Supported by

Coroutines ending on keypress

edited October 2018 in OpenSesame

Hi everyone! I have a problem that should be simple but I don't know how to solve it.

I need to have the following situation in my experiment:
I have a stimulus show for 60 seconds or until keypress. After 50 seconds of stimulus presentation, I have a beep that should go of. If a key is pressed before the 50 seconds, the beep should not go of. My idea of doing this is having the stimulus show with a duration of 0s, followed by coroutines containing the beep (which is a 60s file with the beep at 50s) and keyboard response. Now, the problem is that I can't seem to program the coroutines to last until a key is pressed. I have tried adding the following inline script to the coroutines:

def break_coroutines():

    """A generator that breaks a coroutine when a response is given."""

    # To start, set response to None
    new_keyboard_response1.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 new_keyboard_response1.response is not None:
            items['new_coroutines'].var.duration = 0
            break
        # Also break if the coroutines signals that it's over
        keep_going = yield
        if not keep_going:
            break 

However, when I do that and run the experiment, I get the following message:

"break_coroutines" is not defined

Also, the break_coroutines(): in my code is red.

Thank you in advance for your help.

Comments

  • Hi Slobodanp,

    In recent versions of OpenSesame, coroutines allow you to specify an item that should, when finished, also end the coroutines. So in your case you could use this to have the coroutines end after a keyboard_response. The stop-signal task (one of the examples) shows how you can do this.

    However, when I do that and run the experiment, I get the following message: "break_coroutines" is not defined

    I suspect that the function is defined too late.

    Also, the break_coroutines(): in my code is red.

    I'm not sure what you mean with this, but the function itself is ok!

    Cheers,
    Sebastiaan

Sign In or Register to comment.