Howdy, Stranger!

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

Supported by

Timing out Experiment after specified time.

Hi everyone,

I'm trying to run a switft Letter Comparison Test where participants are asked to judge whether two character strings on screen are the same or different. Their score is determined as the amount of correctly-answered trials in a thirty-second period.

Trouble is, I'm not sure how to terminate my trial sequence after the 30-second time limit. So far, I've built my experiment as normal with a practice and an experimental block (see image below).

I've tried ending the experiment with an inline script at the start of the experiment, as below. I first define a maximum time of 30 seconds (30000 ms) in the Prepare phase, and call time values from the start of my sequence and block. In the Run phase, I have tried setting an "option" variable as 'timeOut' when the counter exceeds the maximum time of 30000ms, and this "option" is then called in the trialSequence to prevent stimuli from running if it is valid.

However, when attempting to run this, OpenSesame returns a

The variable 'time_trialSequence' does not exist.

error. What am I doing wrong here? Am I calling "time_trialSequence" before it is 'created' when trialSequence is run? If so, how do I script this 30-second timeout such that I can call all the variables I need and still initialise the timeout effectively?

I'm running OpenSesame 3.3.9b1 on Ubuntu Linux 20.04. Any help would be very appreciated!


  • Hi @Artabanos,

    This is happening because at the time you define trialTime (trialTime = self.get("time_trialSequence")), the trialSequence object has not started, hence it's time of onset has not been defined.

    You could try is the following:

    (1) define the maxtime as you currently, remove everything else from your timer script.

    (2) at the beginning of your expSequence, define blockTime

    (3) at the beginning of your trialSequence, define your trialTime

    (4) in the settings of your expLoop, use the "break if" option and set it to ([trialTime]-[blockTime] >= [maxtime]. Now, whenever that condition is met, the expLoop will be interrupted and the task will move to whether comes after that loop. If the Break if condition can't include operations, go back to step 3 and add a variable measuring the difference between trialTime and blockTime (let's say you call it timeElapsed), and set the break if condition to [timeElapsed] >= [maxTime].

    Haven't tried implementing this myself but I think it should work.

    Good luck!


    Buy Me A Coffee

  • Hi Fabrice,

    Thank you for your extensive and helpful reply! I didn't actually manage to get your solution to work, but your suggestions did lead me to a solution that ended up doing what I wanted it to do.

    1) Before any loops began, I defined maxTime as 30000 ms well as elapsedTime as an empty integer (using the int() function). This allows the trial loop later to call elapsedTime even though there is no value to this yet. I also allowed both of these values to be called by OpenSesame using the self.experiment.set() function.

    2) Then, I added another inline script as the final step in my trialSequence. This script defines: timeStart = self.get("time_trialBlock") as well as timeOut = self.get("time_LCTstring"). timeStart, in this case, is the time at which the trial block started, and timeOut calls the time at which the last stimulus was presented. timeStart is a static value, whereas timeOut updates every time a stimulus appears on screen.

    3) In the same script, I defined another variable as the difference between these two points in time: elapsedTime = timeOut - timeStart (and, again, set this variable to be used with self.experiment.set())

    4) Finally, in my trialBlock loop, I used the 'break if' function and set this to [elapsedTime]>=[maxTime].

    In this way, trialBlock calls only values already initialised and therefore won't terminate the experiment, and it neatly times out 30000ms (30 seconds) after the start of the trial block.

    Thanks again for your help @Fab , much appreciated!


  • Hi Willem @Artabanos,

    Great stuff! Glad you got it to work and solved the problem! 👍️

    Good luck with your experiment!


    Buy Me A Coffee

  • Hello everyone,

    i´m trying to do the same thing but i´m not able to see my mistake here. I want to implement different block times so i guessed that i needed more scripts, since i was trying to set either one minute or like 52000ms or so. (2 scripts for each block varying in its maxTime)

    After trying to trouble shoot i came across this thread. Maybe you can help me out by giving me either some further instruction or showing me the script that seems to have worked out in the end.

    Here are my scripts so far.

    Since i´m new to OpenSesame, please try explaining step-by-step.

    Thank you in advance.

    Kind regards, Chris😊

  • edited September 2022

    Hi Chris,

    This example demonstrates the principle. You can adapt it to your needs.

    Since i´m new to OpenSesame, please try explaining step-by-step.

    As I see, you are not only new to Opensesame but also to Python. Understanding both is quite useful when using the software and building your experiments. I recommend you try some of the tutorials, and maybe also a Python course. If you have a basic understanding of those things, your coding experience will be much nice ;)


    Buy Me A Coffee

  • edited September 2022


    i‘m quite new to all of this. The Experiment is required for my bachelor thesis. I‘ll try this out First thing in the Morning, thank you so far, Eduard.

  • @Artabanos

    Do you mind sharing your LC task? I am making a pattern comparison task, but I am experiencing difficulties implementing the 30000 ms timeout. Specifically, I am receiving the feedback that my in-line script is missing the required positional argument 'val'. I followed your steps, stating: self.experiment.set(maxTime).

    Did you run into this error while creating your successful task?

    @eduard I attempted implementing the language used in the timer task you shared, however, when using this, the entire task times-out at 30000 ms, rather than the trial block. Additionally, the trial does not run for a complete 30000 ms, it is variable but always ends before the full duration. Does this have something to do with the block_dur and clock_time variables?

    Thank you

  • Hi,

    when using this, the entire task times-out at 30000 ms, rather than the trial block

    There is only one block in the experiment. Sop ending the block means ending the experiment.

    the trial does not run for a complete 30000 ms

    I suppose you mean 3000 ms? How do you know it doesn't do it? In the example there is no logger, so that you can't see how long exactly the block ran. When I add a logger I consistently see durations larger than 3000 which is expected.

    Buy Me A Coffee

  • @eduard

    I am hoping to run each trial block for 30000 ms, or in other words, 30 seconds. Meaning that the two trial blocks will run for separate 30000 ms durations. I personally timed each trial to see how long the trial block duration lasted, and both lasted less than the full duration by a matter of a couple thousand ms.

    I am hoping to run two separate blocks with different stimuli, for 30000 ms each. Is it possible to change the language in the timer OS task you shared, so that I may run each task block separately for a full 30000 ms each?

  • I am quite sure the code works. Can you share your experiment, I shall try to see what is going on

    Buy Me A Coffee

  • Hello,

    My pattern comparison task is too large of a file to attach within this forum, so I have shared my letter comparison task that uses the in-line script you have shared in your timer task. I am hoping to make each of the two trial blocks last for 30000 ms total. Currently, the run time for the first trial block is variable and the second trial block is not running (I am guessing as a result of the maxTime variable). Regardless, I am looking for advice on how to get each trial block to run for a smooth set 30000 ms.

    Thank you!

  • Hi,

    the second trial block is not running

    You need to reset block_dur . Otherwise it will already be at the start larger than 30s

    the run time for the first trial block is variable

    Because the duration of the items inside the actual loop is not in your control, you won't be able to guarantee that the loop will last exactly 30 seconds. The problem is that you depend on the time a participant is taking for their response. Suppose the participants is falling asleep during the first trial, the experiment will never stop, because inside the loop you will wait for an infinite duration until the participants responds. Nevertheless, provided that the participant replies rather quickly, the problem so far was that the timer started in the prepare phase of the experiment. The attached example should be reasonably accurate (I print out the current time to the debug window to show the current duration)


    Buy Me A Coffee

  • @eduard

    Thank you for identifying the error, the task is running exactly as I would like it to be now.

    However, when I attempt to run the task in an external browser, I recieve a notification stating: " Uncaught TypeError: Cannot set properties of undefined (setting 'imports')." Is the language you implemented into the in-line script not compatible with Jatos/external browsers? I am not sure what the setting imports error could be a result of, as this task does not use any outside stimuli.

    Thanks again

  • Indeed, I wrote Python code which is not compatible with Online experimenting. You would need to translate the code to Javascript (and use the javascript inline_script item). Most of the code should be easily copied without any changes, but I am not sure how to take a time sample in javascript. This might help. and maybe, @Fab can you help out once again?

    Buy Me A Coffee

  • FabFab
    edited November 2022

    Hi @mhilliard2, (cc @eduard)

    I had a quick look (am pressed for time) but I think I've cracked it.

    Your code can easily adapted to Javascript for most parts (for example, in Javascript, you just need to use vars.somevariable to define a variable you'd define with var somevariable in Python), but I've had trouble accessing the clock function (clock.time()). I'm not sure whether it is actually accessible from Javascript or not, so I implemented an alternative using Javascript language :

    var currentDateTime = new Date()
    vars.block_start_time = currentDateTime.getTime() / 1000

    It's not as direct as in Python but this does get you the clock's current time in seconds. Because it gets it in seconds and not milliseconds, I've also changed the maximum interval to 30 instead of 30000:

    vars.max_dur = 30 //in seconds

    The rest is a basic adaptation of the Python code to Javascript. Had a quick go and it seems to be working as supposed to but, as I said, I'm in a rush and did this quickly, so I recommend you doublecheck it.

    I tried it from both from OS in a window and through a browser and it seems to work. In your browser, I recommend checking what's going on in the console to keep track of things, which you can do by opening the console through the browser's menu or using CTRL+SHIFT+i in most browsers in Windows:

    Here's my version:

    Hope this helps,


    PS: please be aware that in order to run in a browser and through JATOS, the compatibility check must not detect any problem. This means that the "log all variables" of the logger must be disabled and that you must indicate manually which variables you want to log. For the task to run, I disabled the logging of all variables. You'll need to set the logger up based on what you want to register.

    Buy Me A Coffee

  • Great, Fab!

    Buy Me A Coffee

  • @Fab

    Hello! I hope you are doing well! I made a similar task to the one I attached to this forum, however, it incorporates a series of sketchpad items. In this task, I was hoping to use your script to once again set two testing blocks to break after the 30 second mark. I am only halfway done with the task (as you will notice by the single testing block), but I am having a lot of difficulty getting the test to terminate after 30 seconds. I believe the location of the second inline script may be the issue, but I was hoping that you may take a look as well.

    Thank you!

  • Hi @mhilliard2,

    Before I take a look, I think there are basic things to fix. You're using a loop but have created 30 individual copies of the stimuli. Right now your test1 loop would run 10 x 30 x 30 = 9000 trials... Is that what you intended to do? I believe that you should have a single stimulus slide and keyboard object in that loop and pull the names of the image files to display from the information in the loop. I recommend you read through the documentation and follow the basic tutorials on how to use loops. Once that is fixed, we can take a look at the time limit issue.



    Buy Me A Coffee

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