May 21, 2020 at 4:29 pm #5295crtormaParticipant
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?
CindyMay 21, 2020 at 6:10 pm #5297JeremyKeymaster
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() )
JeremyMay 26, 2020 at 2:32 pm #5421caljonesParticipant
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())
CallieMay 26, 2020 at 4:25 pm #5422JeremyKeymaster
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() )
JeremyMay 26, 2020 at 4:36 pm #5423caljonesParticipant
Thank you very much!
- You must be logged in to reply to this topic.