Display time spent on a trial to the participants

PennController for IBEX Forums Support Display time spent on a trial to the participants

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #6962
    Aymericc
    Participant

    Hi,

    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

    #6963
    amilam
    Participant

    Hi,

    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 3 years, 6 months ago by amilam.
    #6965
    Aymericc
    Participant

    Hi amilam,

    Thanks a million for your reply. I tried the code you provided, and it works perfectly for my purpose!

    Aymeric

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.