JavaScript sleep and cross trial constraints
Dear all,
sorry if these are newbie questions but I did not find information in the documentation or forum. Two questions. We have cross trial timing and randomization constraints:
(1) I could solve cross trial timing with inline_javascript. However, the only way I got this to work was using a tight loop and burning cpu cycles. None of the suggestions I found online mostly including setTimeout worked. Is there a JavaScript alternative for sleep working in OSWeb?
(2) I have to avoid repetitions of certain trial types. In OpenSesame this was easy using constrain. This appears not to work in OSWeb, neither can I load loops from files. Is there an accessible way to constrain randomization in OSWeb? I'm aware that I could use a manually defined sequential table. However, then order is the same for all participants in JATOS.
Thanks a lot for any input!
Andreas
Comments
Hi Andreas,
I am not sure I fully understand your first point, but both problems seem to be fixable with the inline javascripts, no? You could implement your own randomization in it, and set experimental variables once you are done. So basically, create some conditions/timings in list and combine them in a way that makes sense given your constraints. Once you are done, you can set the variables with
vars.set('timing_variable','timing_value')or whatever the precise code in javascript is.Does that help?
Eduard
Hi Eduard,
thank you for your input!
The short version of the first question was: Is there a JavaScript equivalent for clock.sleep?
My JavaScript skills are very limited. With my second question I was hoping for an accessible solution without having to learn lots of JavaScript. But if this appears not to be possible, right?
Thanks a lot!
Andreas
Hi Andreas,
Sorry for the late reply! Unfortunately, my Javascript skills are also close to non-existent. So, I would also have to google.
I think getting away without learning any javascript will be challenging, particularly for slightly more complex study designs. But maybe you can find some experiments on the forum that used javascript and use it as inspiration.
Sorry and good luck,
Eduard
Hi @widmann.
Sadly no, there are no equivalents for clock.sleep in JavaScript. This is one of the main reasons why it is impossible to port the Python inline script items from OpenSesame to Osweb. Python by nature is a linear programming language, which can be paused, while Javascript is asynchronous, and thus cannot be paused (Google these terms if you like to know more).
There are ways to sort of mimic a sleep period in JavaScript, but these are not easy, and most likely will involve a callback structure (such as with setTimout) that is not possible to achieve with inline_javascript items.