Reply To: About timeouts

PennController for IBEX Forums Support About timeouts Reply To: About timeouts

#10799
Jeremy
Keymaster

Hi,

callback commands inform the script of what to do whenever the relevant event happens, and immediately move on to the next line in the script. By contrast, wait commands halt the execution of the script until the relevant event happens, after which only do they move on to the next line in the script. When you have these lines in a script:

newTimer("timeout", 5000).start() // A
,
newVar("RT").global().set( v => Date.now() ) // B
,
newKey("answerKey","SK").log("all").callback( getTimer("timeout").stop() ) // C
,
getTimer("timeout").wait() // D
,
getVar("RT").set( v => Date.now() - v ) // E

The script first executes (A): it starts a 5s timer and moves on to (B) without waiting for the timer to elapse (because there is no wait command in A). At (B), which is executed immediately after (A), the scripts sets the Var element to the current timestamp, ie. a timestamp that corresponds to when the timer was started. The script immediately moves on to (C), which evaluates the callback command: here, the script learns that whenever the participant presses S or K, the command getTimer("timeout").stop() should take effect. But importantly, there is no wait command in (C) so the script immediately moves on to (D), but it now keeps in mind what should happen were the participant to press S or K at any point. At (D) the script sees a wait command so it stays on (D) until the timer has stopped. This could happen because the 5s have elapsed, the normal course of events for a timer; or it could happen because the timer was stopped early, which is precisely what we instructed the script to do if the participant ever presses S or K, in the preceding callback command. So when the timer stops, regardless of which scenario we’re in, the script then moves on to (E) and sets the Var element to the current timestamp minus the previous one. If we’re in a scenario where the participant didn’t press S or K, then the script must have reached this line after waiting 5s, so the subtraction will result in that duration. But if we’re in a scenario where the timer was stopped because the user pressed S or K, then it hasn’t been 5s yet, and the subtraction will reflect that, and the result of the subtraction will be a lesser value. Once the Var element has been set, the script immediately moves on to the next line (if any)

Jeremy