break loop based on timing does not work in OSweb
I have an issue breaking a loop in OSweb based on the time that has passed.
After the instructions, that finish with a key response (finish_instructions), I have a loop with a long list of trials (see attachment). After 1 minute I want the loop to break. I'm taking the trial time and taking from it the time at the end of the instructions cause the time people are reading the instructions shouldn't be counted.
In the loop item I put for break if: "[time_trial]-[time_finish_instructions]>60000"
This works perfectly in a standard OS run or quick run, but in OSweb (test experiment in external browser) the loop just keeps going long after a minute has passed. To try to debug I printed [time_trial],[time_finish_instructions], and the difference on the screen for every trial. This looks perfectly sensible in standard OS, but in OSweb time_trial always stays zero (its init value at the start of the experiment) and does not exist if it is not initialised (error: variable 'time_trial' not present in var store). Do sequence elements not get a time stamp in OSweb?
Tried a work-around with a blank sketchpad element, or keyboard response starting the trial and using the time stamp of those but this gives the same problem.
Insights on what is going on here and how I could go about a loop that breaks after a certain amount of time in an online experiment would be very much appreciated.
Thanks!
Louisa
Comments
Hi Louisa,
I don't know what could cause the issue with OsWeb, but one work around could be to directly access a clock object and set the current time. For that you could probably just use an inline_script item and then code with javascript a single line that measure the current time, saves it in a var object.
Perhaps that could work?
Eduard
Hi Eduard,
Thanks for your reply.
I solved it along the line you suggested. Detailing my solution here in case it's helpful for others.
Louisa
------------------------
A Java inline script before the loop sets the start time:
vars.startTime = Date.now();
------------------------
A second Java inline script positioned at the end of the trial sequence evaluates the time that has passed and sets a flag to 1 if more than 1 minute has passed:
if ((Date.now() - vars.startTime) > 60000){
vars.flag = 1;
}
------------------------
The loop is set to break if: "flag = 1"