PennController for IBEX › Forums › Support › Can we randomize time with newTimer() ? › Reply To: Can we randomize time with newTimer() ?
You would need to use the method that you use with the Var element named localRT to dynamically calculate the duration in another Var element, and set the duration of a final Timer element using that Var element. Be aware, though, that each command takes a non-null time to be executed, so the value of a Var element set the way localRT is set is not guaranteed to be exact to the millisecond:
newVar("localRT").set(v=>Date.now()), newKey("keypress1","SK").wait(), getVar("localRT").set(v=>Date.now()-v),
Both newKey
and wait
(and set
too, to some extent) take some time to be executed, which means that Date.now()-v
might represent a time difference that’s slightly greater (by up to a couple milliseconds) than the actual time that passed between the creation of the Key element and a keypress. Also, all the commands that come after the wait
command of the previous Timer element (timer_D3) and before newVar
take time to be executed too, so those few milliseconds are not taken into account either if you create the Var element a few commands after wait
ing for the end of the previous Timer element
Moreover, your actual trials won’t have the wait
command on the Key element, but rather on the Timer element named timer-RT, so that’s the one after which you would need to set a Var element like localRT. So simplifying the structure a little bit, you would have something like this:
timerd1duration = 400+Math.round(1200*Math.random()) , newTimer("timer-D1",timerd1duration).start().wait() , getText("D1").remove() , newText("cue", "*").color("green") , newTimer("timer_cue_D2",100).start().wait() , getText("cue").remove() , newText("D3", "+").color("pink") , newTimer("timer_D3",400).start().wait() , newVar("newTimerDuration").set( v=>Date.now() ) , getText("D3").remove() , newTimer("timer-RT",1700).start() , newImage("imagens", row.imagem).size(500, 200) , newText("cruz_central", "+").color("black") , newCanvas("center", 150,150).add( "center at 50%" , "center at 50%" , getImage("imagens")).print() , newKey("keypress1","SK").log().callback( getTimer("timer-RT").stop() ) , getTimer("timer-RT").wait() , getVar("newTimerDuration").set( v=> 3500 - timerd1duration - (Date.now()-v) ) , newTimer("separacao").set( getVar("newTimerDuration") ).start() , getKey("keypress1").disable(),getText("cruz_central"),getCanvas("center").remove() , newText("+").color("yellow") , getTimer("separacao").wait()
Finally, let me point that any reviewer who would argue that the design is not replicated using the method I suggested earlier either would not understand it, or (unless I myself misunderstood the design as described in the excerpt you quoted) would be completely dishonest in their assessment (keeping in mind that there is a myriad of other technical points of divergence when implementing the same design using different codes and engines)
Jeremy