Timing out Experiment after specified time.
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!
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
maxtimeas you currently, remove everything else from your
(2) at the beginning of your
(3) at the beginning of your
trialSequence, define your
(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
expLoopwill 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
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.
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
maxTimeas 30000 ms well as
elapsedTimeas an empty integer (using the
int()function). This allows the trial loop later to call
elapsedTimeeven though there is no value to this yet. I also allowed both of these values to be called by OpenSesame using the
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
timeOutcalls the time at which the last stimulus was presented.
timeStartis a static value, whereas
timeOutupdates 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
4) Finally, in my trialBlock loop, I used the 'break if' function and set this to [elapsedTime]>=[maxTime].
In this way,
trialBlockcalls 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!
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😊
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 ;)
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.
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?
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.
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
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.
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)
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.
Hi @mhilliard2, (cc @eduard)
I had a quick look (am pressed for time) but I think I've cracked it.
vars.somevariableto define a variable you'd define with
var somevariablein Python), but I've had trouble accessing the clock function (
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:
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.
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.
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.