PennController for IBEX › Forums › Support › Display time spent on a trial to the participants
- This topic has 2 replies, 2 voices, and was last updated 2 years ago by
Aymericc.
-
AuthorPosts
-
May 15, 2021 at 5:19 am #6962
Aymericc
ParticipantHi,
I am planning on creating a “long” experiment. By long experiment, I mean that there would be only one trial, but it may take about 30 minutes for the participants to finish this task.
If I read the documentation right, there is a “timer” option to limit the time that the participant can spend on this trial.I am wondering whether it is possible to display on the screen the time that was spent since the beginning of the trial. The idea behind is that I wish the participants can easily monitor themselves about the time they spend on this trial.
Thank you in advance for your response. Please tell me if I need to clarify anything!
Aymeric
May 15, 2021 at 5:40 am #6963amilam
ParticipantHi,
This is a sample code that illustrates what are you looking for:
PennController.ResetPrefix(null) // Keep here newTrial( newVar("finishTime").set(v=>Date.now()) , newText("countDown", "0m0s").print() , newTimer("updateCountdown",1000).callback( newVar("difference") .set(getVar("finishTime")).set(v=>-v+Date.now()) , // Transform the Var element into an appropriately formatted string getVar("difference") .set(v=>Math.trunc(v/60000)+"m"+Math.round((v/1000)%60)+"s") , getText("countDown").text(getVar("difference")) , // Relaunch the timer to update again in 1s getTimer("updateCountdown").start() ).start() // Don't forget to start the timer the initially , newButton("Click me").print().wait() , getVar("finishTime").set(v=>Date.now()) // This will effectively stop the countdown , getTimer("updateCountdown").test.running() .success( newText("You clicked in time!").print() ) .failure( newText("You were too late").print() ) , newButton("Finish").print().wait() )
Hope it helps!
-
This reply was modified 2 years ago by
amilam.
May 16, 2021 at 4:40 am #6965Aymericc
ParticipantHi amilam,
Thanks a million for your reply. I tried the code you provided, and it works perfectly for my purpose!
Aymeric
-
This reply was modified 2 years ago by
-
AuthorPosts
- You must be logged in to reply to this topic.