Reply To: While loop compatability?

PennController for IBEX Forums Support While loop compatability? Reply To: While loop compatability?

#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