Stopping a timer

PennController for IBEX Forums Support Stopping a timer

This topic contains 2 replies, has 2 voices, and was last updated by Avatar sabrina 1 month ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #7283
    Avatar
    sabrina
    Participant

    Hello,
    I am working on a letter search task which should follow this process:

    – Fixation cross: 1000ms
    – Target letter in uppercase: 500ms
    – Pseudoword in lowercase: 500ms
    Blank screen until response or time-out after 2000ms
    – Blank screen interval: 1000ms (obligatory)
    – Automatic initiation of next trial

    The problem is that the timer in the first blank screen interval does not react to the key press, meaning it always waits until time-out.
    I tried to use the solution described here: https://doc.pcibex.net/timer/#timer-stop
    It’s probably just some incorrectly placed brackets, but I’ve been trying to find the problem for hours, without success.

    Here is what the code looks like:

    Template( "testitems_laura.csv" , 
        row => newTrial( "exp_trial",   
            // Display all Text elements centered on the page, and log their display time code
            defaultText.center().print("center at 50vw","middle at 50vh").log()
            ,
            // Automatically start and wait for Timer elements when created, and log those events
            defaultTimer.log().start().wait()
            ,
            // Cross, shown on screen for 1000ms
            newText("cross","<b>+</b>"),
            newTimer("crossTimer", 1000),                       
            getText("cross").remove()
            ,
            // Target letter, shown on screen for 500ms  
            newText("targetletter", row.targetletter),
            newTimer("targetletterTimer", 500),          
            getText("targetletter").remove()
            ,
             // Word, shown on screen for 500ms   
            newText("pseudoword",row.pseudoword),
            newTimer("pseudowordTimer", 500),          
            getText("pseudoword").remove()
            ,
            //Blank screen shown for 2000ms or until D or K is pressed
            newText("wait"," ").print(),  
            newTimer("delay", 2000)
            .start()
            ,
            newKey("stop early", "FJ")
            .callback( getTimer("delay").stop()) 
            ,
            getTimer("delay")
            .wait()
            ,
            getText("wait").remove(),
            
            
            // 1000ms blank screen
            newTimer("break", 1000).start().wait())   
        
            // End of trial, move to next one
        
        
        .log("Group", row.group)      // Append group to each result line
        .log("Condition", row.condition)  // Append condition to each result line
        .log("Expected", row.expected )  // Append expectped to each result line
        .log("affixType", row.affixtype ) // Append affix type to each result line    
    )
    #7284
    Jeremy
    Jeremy
    Keymaster

    Hello,

    Your logic is good, but you start and wait for all the Timer elements you create by default, so the “stop early” Key element is created only after the “delay” Timer element has ended. Move newKey("stop early", "FJ").callback( getTimer("delay").stop()) just above newTimer("delay", 2000) and it should work (you don’t need the start and wait commands on the “delay” Timer element—nor on the “break” one, since those are executed by default)

    Jeremy

    #7293
    Avatar
    sabrina
    Participant

    Hi Jeremy,

    thank you very much for your fast and helpful reply, you’re really doing an amazing job here!

    So this works indeed, but only after I removed all the unnecessary start and wait commands. Here is the code again, just in case anyone else needs it:

            // Cross, shown on screen for 1000ms
            newText("cross","<b>+</b>"),
            newTimer("crossTimer", 1000),                       
            getText("cross").remove()
            ,
            // Target letter, shown on screen for 500ms  
            newText("targetletter", row.targetletter),
            newTimer("targetletterTimer", 500),          
            getText("targetletter").remove()
            ,
             // Word, shown on screen for 500ms   
            newText("pseudoword",row.pseudoword),
            newTimer("pseudowordTimer", 500),          
            getText("pseudoword").remove()
            ,
            //Blank screen shown for 2000ms or until D or K is pressed
            newText("wait"," ").print(),
            newKey("stop early", "FJ").callback(getTimer("delay").stop()),
            newTimer("delay", 2000),
            getTimer("delay"),
            getText("wait").remove(),
            
            
            // 1000ms blank screen
            newFunction( ()=>$("body").css("background-color","pink") ).call(), //only for testing, can be removed
            newTimer("break", 1000), 
            newFunction( ()=>$("body").css("background-color","black") ).call() //only for testing, can be removed
        
            // End of trial, move to next one

    Thanks again,
    Sabrina

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.