While loop compatability?

PennController for IBEX Forums Support While loop compatability?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #5295
    crtorma
    Participant

    Hi Jeremy,

    I’m trying to set up an experiment that times out and moves on if a participant doesn’t respond within a certain time frame. I was planning on setting a timer and using an empty while loop with a conditional statement that checks if the selector is not selected and the timer is still running to hold the experiment until one of those two things changes — but the debugger is telling me that the while isn’t appropriate syntax. Is there a way to make it compatible / specific syntax for this?

    Best,

    Cindy

    #5297
    Jeremy
    Keymaster

    Hi Cindy,

    Yes, you cannot freely inject some javascript inside a PennController trial. There is a Function element, but it’s more for running independent routines than to make PennController elements interact with native javascript code.

    Your case is a standard setup in PennController, here is what you can do:

    newTrial(
        newText("Left").print("right at 48vw", "middle at 50vh"),
        newText("Right").print("left at 52vw", "middle at 50vh")
        ,
        newSelector("choice")
            .add( getText("Left") , getText("Right") )
            .callback( getTimer("timewindow").stop() )
        ,
        newTimer("timewindow", 5000).start().wait()
        ,
        clear()
        ,
        getSelector("choice").test.selected()
            .success( newText("Thank you").print() )
            .failure( newText("Too slow!").print() )
        ,
        newButton("Finish").print().wait()
    )

    Jeremy

    #5421
    caljones
    Participant

    Hello,
    I am also trying to create a task where if the participant doesn’t respond in a certain amount of time, the task moves onto the next trial. However, the response is a key press, and for some reason my code doesn’t seem to move on after a key press. I’ve attached what I have below, could you tell me what I’m doing wrong?

    newTrial("keySelection"
            newImage(variable.ImgFile)
                .size(650,452)
                .print()
           , 
            newKey("FJ")
                .log()
                .wait()
            ,
            newSelector("timeout")
                .add (getKey("FJ"))
                .callback(getTimer("timerout").stop())
            ,
            newTimer("timerout", 2000)
                .start()
                .wait()
            ,
            clear()
            ,
            getSelector("timeout") .test.selected()
                .success(newText(" ") .print())
                .failure(newText("Too slow!") .print())

    Thanks,
    Callie

    #5422
    Jeremy
    Keymaster

    Hello Callie,

    Your script will first read the Image element lines and accordingly add a 650×452 image to the page using the file specified by variable.ImgFile, then it will read the Key lines and accordingly listen to keypresses on F or J and pause its execution there until one of the two keys has been pressed, because of the wait command. Only after a keypress has happened will it release its execution and reach the commands below, starting with the newSelector line. This means that it will reach the Timer element’s wait command only after F or J has been pressed, at which point the script will wait 2 seconds before releasing its execution and reaching the clear and Selector’s test commands.

    You probably don’t want to use a Selector element in your case: Selectors take elements that are displayed on the page and make them clickable. Because a Key element is not something that you can click on, your Selector will effectively never complete.

    What you want to do instead is use callback on your Key element, so that the commands that you put in the callback are executed only after the F or J key is pressed, but without pausing the execution of your script so it can immediately launch the Timer element:

    newTrial("keySelection"
        newImage(variable.ImgFile)
            .size(650,452)
            .print()
        , 
        newKey("FJ")
            .log()
            .callback( getTimer("timerout").stop() )
        ,
        newTimer("timerout", 2000)
            .start()
            .wait() // pause execution until Timer stops
        ,
        clear()
        ,
        getKey("FJ").test.pressed()
            .success( newText(" ").print() )
            .failure( newText("Too slow!").print() )

    Jeremy

    #5423
    caljones
    Participant

    Thank you very much!

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