PennController for IBEX › Forums › Support › Can we randomize time with newTimer() ?
- This topic has 58 replies, 2 voices, and was last updated 2 years, 7 months ago by Larissa_Cury.
-
AuthorPosts
-
March 21, 2022 at 5:25 pm #7933JeremyKeymaster
Add
newVar("practiceRTs").set( [] ) ,
beforejump(startsWith("p_trial"))
to reset the Var element, and yes, if you drop/1000
you will have a value in seconds rather than in millisecondsJeremy
March 21, 2022 at 5:45 pm #7934Larissa_CuryParticipantAll right! Thank you!!! Considering the Var method above,
timerd1duration = 400+Math.round(1200*Math.random()) // <------------- are we creating an object (such as we do in R?) i tried this, but it returned me an error. Shouldn't It be a a new Var too? , newTimer("timer-D1",timerd1duration).start().wait() , getText("D1").remove() ,
what about the D1 text? shouldn’t I keep it too? Would it be sth like this?
timerd1duration = 400+Math.round(1200*Math.random()) // (which returned the error) , newText("D1", "<br><b>+</b>") .cssContainer({ "font-size":"100px", "color":"blue"}) .center() .print() , newTimer("timer-D1",400+Math.round(1600*Math.random())) .start() .wait() , getText("D1") .remove() ,
etc
- This reply was modified 2 years, 7 months ago by Larissa_Cury.
March 21, 2022 at 5:50 pm #7936Larissa_CuryParticipantorrrrr, should I do this =
getVar("newTimerDuration").set( v=> 3500 - timerd1duration - (Date.now()-v) )
replacing timerd1duration by “timer-D1”, since it’s the label for my d1 timer?
March 21, 2022 at 5:58 pm #7937JeremyKeymasterIf you’re referring to the code from this message, it’s not a full code: it’s a streamlined excerpt of your code to which I added the relevant bits to use the Var method
timerd1duration = 400+Math.round(1200*Math.random())
creates a javascript variable namedtimerd1duration
that will store the generated random value (which, in the code from my message, I use when creating the Timer element named timer-D1 and when calculating the duration of the last Timer element). I tookgetText("D1").remove()
directly from your code, it’s your call to keep it or not, depending on what you want to happen at that time in the trialIf you use
newTimer("timer-D1",400+Math.round(1600*Math.random()))
then there’s no point in usingtimerd1duration = 400+Math.round(1200*Math.random())
. You also will get a duration between 400ms and 2000ms (because 400+1600=2000)."timer-D1"
is a string (as you can tell by the double quotes) so you don’t want to include that in an arithmetic operationJeremy
March 21, 2022 at 6:02 pm #7938Larissa_CuryParticipantOhhh, all right! Then, I should do this, right:
, timerd1duration = 400+Math.round(1200*Math.random()) ,
I just didn’t understand why 1200 and not 1600 ?
Best,
March 21, 2022 at 6:05 pm #7939JeremyKeymaster400+1200=1600, but 400+1600=2000. I was under the impression that you wanted a random duration between 400ms and 1600ms, not between 400ms and 2000ms
Also, I’m just realizing that I reference that variable in a function in
.set
on the Var element, and becausetimerd1duration
is set in aTemplate
environment, by the time the function fromset
is executed it will always have the value it got in the last generated trial, so my code won’t have the desired outcome. More details on the timeline of javascript code injection on this pageJeremy
March 21, 2022 at 6:09 pm #7940Larissa_CuryParticipantOhhhhhhh, now I got the reason why 1200! I’m sorry, that’s right. I need between 400 and 1600 exactly. Thank you! What do you mean that won’t work? What should I do to change it for the desirable outcome?
March 21, 2022 at 6:14 pm #7941Larissa_CuryParticipantThat’s what I’ve done so far:
Template("tabela-target.csv" , row => newTrial("trial_2_center_cue_UP", defaultText .center() .cssContainer({"position": "absolute", "top": "50%", "left": "50%", "transform": "translate(-50%, +50%)"}) .print() , newText("D1", "<br><b>+</b>") .cssContainer({ "font-size":"100px", "color":"blue"}) .center() .print() , timerd1duration = 400+Math.round(1200*Math.random()) , newTimer("timer-D1",timerd1duration) .start() .wait() , getText("D1") .remove() , newText("cue", "<br> <b>*</b>") .cssContainer({ "font-size":"100px", "color":"green"}) .center() .print() , newTimer("timer_cue_D2",100) .start() .wait() , getText("cue","D2") .remove() , newText("D3", "<br> <b>+</b>") .cssContainer({ "font-size":"100px", "color":"pink"}) .center() .print() , newTimer("timer_D3",400) .start() .wait() , getText("D3") .remove() , newVar("newTimerDuration").set( v=>Date.now() ) , newTimer("timer-RT",1700) .start() , newImage("imagens", row.imagem) .size(500, 200) , newText("cruz_central", "<br> <b>+</b>") .cssContainer({ "font-size":"100px", "color":"black"}) .center() .print() , //para cima// newCanvas("center", 150,150) .add( "center at 50%" , "center at 50%" , getImage("imagens")) .cssContainer({ "position": "absolute", "margin-top": "85px"}) .center() .log() .print() , newKey("keypress1","SK") .log() .callback( getTimer("timer-RT").stop() ) , getTimer("timer-RT").wait() , getVar("newTimerDuration").set( v=> 3500 - timerd1duration - (Date.now()-v) ) , newTimer("wait-separacao").set( getVar("newTimerDuration") ) .start() , getKey("keypress1").disable(), getText("cruz_central"), getCanvas("center") .remove() , newText("separacao", "<br> <b>+</b>") .cssContainer({ "font-size":"100px", "color":"yellow"}) .center() .print() , getTimer("wait-separacao") .wait() ) .log("imagens", row.imagem) .log("item", row.versao) );
that’s the error I get = Invalid duration for Timer “wait-separacao” (newTrial: 47)…What should I do?
- This reply was modified 2 years, 7 months ago by Larissa_Cury. Reason: include information
- This reply was modified 2 years, 7 months ago by Larissa_Cury. Reason: add information
March 21, 2022 at 6:27 pm #7944JeremyKeymasterThe issue I’m raising in my previous message means one needs to revise the approach if one wants to use the Var method. I can’t spend more time on this today, but feel free to look for an alternative method yourself
Jeremy
March 21, 2022 at 6:31 pm #7945Larissa_CuryParticipantThank you, Jeremy! I’m total new to Java script (all I know concerns the Pcibex script itself)…I read the documentation you’ve recommended, but I couldn’t find a solution to solve the set problem. I really wanted to use this approach. Thank you once more for your time and patience.
- This reply was modified 2 years, 7 months ago by Larissa_Cury. Reason: add information
March 22, 2022 at 1:34 pm #7949JeremyKeymasterHi 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
March 23, 2022 at 9:42 am #7954Larissa_CuryParticipantDear Jeremy,
Thank you for your kind answer as always. I’ve went through what we’ve discussed and I wasn’t able to notice before that the 4000 timeout trial had, indeed, the same formula as the original paper had (D1 + D2 + D3 + DRt + DWait = 4000 equals DWait = 3500 – D1 – DRT), I’m so sorry I took your time for trying to explaining that to me, but I really appreaciate your kindness, so, thank you once more. and thank you more going over the alternative method, I didn’t have a clue about using the Java option, so i’m sure that will contribuite for my future codes! I’ve already updated the whole model with the 4000 timeout approach, I only have 2 final concerns:In order to use this approach to the practice trial, I’ve ajusted the Wait timer to 6000, not 4000, since the feedback takes 2000ms, like this:
//////////////////////////////////////////trial_1 - no_cue// PARA CIMA/LEFT////////////////////////////////////////////////////// Template("tabela-target_left.csv" , row => newTrial("p_trial_1_no_cue_UP", defaultText .center() .cssContainer({"position": "absolute", "top": "50%", "left": "50%", "transform": "translate(-50%, +50%)"}) .print() , newTimer("wait-separacao",6000).start() , newText("D1", " <br> <b>+</b>") .cssContainer({ "font-size":"100px", "color":"blue"}) .center() .print() , newTimer("timer-D1",400+Math.round(1200*Math.random())) .start() .wait() , getText("D1") .remove() , newText("cue", "<br> <b>+</b>") .cssContainer({ "font-size":"100px", "color":"green"}) .center() .print() , newTimer("timer_cue_D2",100) .start() .wait() , getText("cue","D2") .remove() , newText("D3", "<br> <b>+</b>") .cssContainer({ "font-size":"100px", "color":"pink"}) .center() .print() , newTimer("timer_D3",400) .start() .wait() , getText("D3") .remove() , newTimer("timer-RT",1700).start() , newImage("imagens", row.imagem) .size(500, 200) , newText("cruz_central", "<br> <b>+</b>") .cssContainer({ "font-size":"100px", "color":"black"}) .center() .print() , //para cima// newCanvas("center", 150,150) .add( "center at 50%" , "center at 50%" , getImage("imagens")) .cssContainer({ "position": "absolute", "margin-top": "85px"}) .center() .log() .print() , newVar("localRT").set(v=>Date.now()), newKey("keypress1","SK") .log() .callback( getTimer("timer-RT").stop() ) , getTimer("timer-RT").wait() , getKey("keypress1").disable(), getText("cruz_central").remove() , getCanvas("center").remove() , getVar("localRT").set(v=>Date.now()-v), newVar("practiceRTs",[]).global().set(v=>[...v,getVar("localRT").value]) , newVar("accurate", []).global() , getKey("keypress1") .test.pressed("S") .success( newVar("positiveFeedback").set( getVar("localRT") ).set( v=> "Correto! Você demorou "+v+"ms para responder" ) , newText("success") .text( getVar("positiveFeedback") ) .cssContainer({"font-size":"30px", "text-align":"center", "margin-top":"255px","font-family":"Comic Sans MS", "color":"green","white-space":"nowrap"}) , getVar("accurate").set(v=>[...v,true]) ) .failure( newVar("negativeFeedback").set( getVar("localRT") ).set( v=> "Incorreto! Você demorou "+v+"ms para responder" ) , newText("failure") .text( getVar("negativeFeedback") ) .cssContainer({"font-size":"30px", "text-align":"center", "margin-top":"255px","font-family":"Comic Sans MS", "color":"red","white-space":"nowrap"}) , getVar("accurate").set(v=>[...v,false]) ) , newTimer("wait-success",2000) //timer for the success or failure messenge .start() .wait() , getText("success") .remove() , getText("failure") .remove() , newText("separacao", "<br> <b>+</b>") .cssContainer({ "font-size":"100px", "color":"yellow"}) .center() .print() , getTimer("wait-separacao").wait() ));
It seems to me that it’s working just fine, I’d just like to check if the math is right, is it?
Btw, I wasn’t able to fiz the “come back” button as you’ve explained me to do, it keeps on duplicating the trials, I’m sure I’ve did something wrong, but I don’t know what:
newText("instructions-14","<p><center> Se você quiser praticar de novo, clique aqui:") .cssContainer({ "font-size":"22px", "text-align": "center" }) .center() .print() , newVar("practiceRTs").set( [] ) // --------------------------------- here (I've tried to put it before the jumping inside the callback(), but it didn't work too (I probably did sth wrong, though) , newButton("come back","PRATICAR DE NOVO") .callback(jump(startsWith("p_trial")) , end() ) .css("margin","1.5em") .center() .print()
best,
- This reply was modified 2 years, 7 months ago by Larissa_Cury. Reason: add relevant information to the post
March 23, 2022 at 11:32 am #7957JeremyKeymasterHi Larissa,
The math sounds good to me too: the max duration of timer-D1 is 1600ms, then timer_cue_D2 is 100ms and timer_D3 is 400ms, the max (effective) duration of timer-RT is 1700ms, and you add the 2000ms duration of wait-success, which gives you a max total of 5800ms, so by the time your script reaches
getTimer("wait-separacao").wait()
it will still still have at least 200ms to wait (or more, if timer-D1 was shorter and/or the participant pressed a key before the end of the 1700ms of timer-RT)You need to place
newVar("practiceRTs").global().set( [] ) ,
before beforejump(startsWith("p_trial"))
in thecallback
command, not beforenewButton
, but I forgot to include.global()
in my message above, so mea culpaJeremy
March 23, 2022 at 1:19 pm #7958Larissa_CuryParticipantDear Jeremy,
Huhh….I guess I’m still doing sth wrong, ’cause it is still couting the 24 trials twice, let me show it you:
newButton(“come back”,”PRATICAR DE NOVO”)
.callback(newVar(“practiceRTs”).global().set( [] ),jump(startsWith(“p_trial”)) , end() )
.css(“margin”,”1.5em”)
.center()
.print()
?I still get: “Você acertou 14 do total de 48” (which means you’ve got 14 out of 48)
ps: do you think that maybe setting 5800 rather than 6000 would be more precise? My idea was: “ok, I have to show a 2000ms feedback, so I’ll just count this time”
- This reply was modified 2 years, 7 months ago by Larissa_Cury. Reason: add a question
March 23, 2022 at 1:55 pm #7960JeremyKeymasterThe Var element named “practiceRTs” (
which is the one you brought up in your message— EDIT: my bad, the lines of code that refer to that element in your message actually concern another question) keeps track of reaction times, not of accuracy. You need to reset the Var element that keeps track of accuracy tooJeremy
- This reply was modified 2 years, 7 months ago by Jeremy. Reason: correction
-
AuthorPosts
- You must be logged in to reply to this topic.