Reply To: Can we randomize time with newTimer() ?

PennController for IBEX Forums Support Can we randomize time with newTimer() ? Reply To: Can we randomize time with newTimer() ?

#7949
Jeremy
Keymaster

Hi Larissa,

This should work:

Template("tabela-target.csv" , row => 
  newTrial("trial_2_center_cue_UP",
    defaultText
        .center()
        .bold()
        .cssContainer({"position": "absolute",
                       "top": "50%",
                       "left": "50%",
                       "transform": "translate(-50%, +50%)",
                       "font-size": "100px",
                       "margin-top": "1em"})
        .print()
    ,
    newText("D1", "+").color("blue")
    ,
    newVar("timer-D1-duration").set( 400+Math.round(1200*Math.random() ) )
    ,
    newTimer("timer-D1", 1).set( getVar("timer-D1-duration") ).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()
    ,
    getText("D3").remove()
    ,
    newVar("newTimerDuration").set( v=>Date.now() )
    ,
    newTimer("timer-RT",1700).start()
    ,
    newText("cruz_central", "+").color("black")
    ,
    //para cima//
    newCanvas("center", 500,200)
        .add( "center at 50%" , "center at 50%" , newImage("imagens", row.imagem).size(500, 200) )
        .log()
        .print("center at 50vw", "top at 85px")
    ,
    newKey("keypress1","SK")
        .log("all")
        .callback( getTimer("timer-RT").stop() )
    ,
    getTimer("timer-RT").wait()
    ,
    getVar("newTimerDuration").set( v=> 3500 - getVar("timer-D1-duration").value - (Date.now()-v) )
    ,
    newTimer("wait-separacao", 1).set( getVar("newTimerDuration") ).start()
    ,
    getKey("keypress1").disable(),
    getText("cruz_central").remove(),
    getCanvas("center").remove()
    ,
    newText("separacao", "+").color("yellow")
    ,
    getTimer("wait-separacao").wait()
  )
  .log("imagens", row.imagem)
  .log("item", row.versao)
)

Feel free to edit the command on the Canvas element .print("center at 50vw", "top at 85px") if the image does not appear where you would like it to appear (I suspect that you want instead is "middle at 50vh" in place of "top at 85px", but it’s your call)

I have tested this with one trial twice, and the total duration of the trial was around 4040ms both times

Jeremy