Howdy, Stranger!

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

Supported by

[solved] Code to exit the loop after defined time

edited October 2015 in OpenSesame

Hi, I recently started using OpenSesame. I am using OpenSesame 2.94

I am trying to design a simple experiment where a sound clip plays for certain duration (say 10 sec) and while the sound is being played participants are suppose to see a series of visual stimuli.

I tried using the sampler and it plays the clip, and i present the visual stimuli using a loop but i want the loop to break as soon as the sound clip stops..Can anyone suggest me how to break the loop based on specified time using inline script ?


  • edited 10:07AM


    You can keep track of time, while being in a loop.

    The way to do that, is to first indicate a start time right before you enter the loop, by means of start_time = self.time().
    Of course you also need to know the duration of your sound stimulus. Let's call the duration duration. Your loop would look something like this:

       end_loop = False
       duration = 3000
       start_time = self.time()
       while end_loop == False:
              current_time = self.time() - start_time
              if current_time >= duration:

    Does this make sense?



  • edited 10:07AM

    Thanks a lot Josh !

  • edited April 2016

    Also you can use the sampler function "is_playing".

    This is an example of and old experiment that used that : ) Hope It will help to you!

    audio = self.get("audio")
    my_canvas.image(exp.get_file(imagen), y = 325)
    my_sampler = sampler(exp, exp.get_file(audio))
    # this will display the canvas until the audio stops 
    #  you can put extra conditions to break  
    while my_sampler.is_playing() == True:
Sign In or Register to comment.