PennController for IBEX › Forums › Support › Quit Trial after 3rd Attempt › Reply To: Quit Trial after 3rd Attempt
![](https://www.pcibex.net/wp-content/uploads/2018/10/IMG_8365-e1540835663655-150x150.jpg)
Hello Sam,
I see how things become tricky here: in order to reach the end of the trial, you will need to validate the Button’s wait command. This is fine as long as you give the correct answer, because then the test on your TextInput is a success. However, you also want to end your trial after 3 wrong answers, which means validating the wait, but we’ve already established that this situation corresponds to a failed test on your TextInput, so your wait command won’t be validated!
One solution here is to not call wait on this specific button, but on another one instead, and handle your tests in a callback instead. I’m pasting a full functional script below: I slightly rearranged your code to my preferences, but of course feel free to move things back to how they were. I also updated the command names to reflect the changes in PennController 1.7. And finally, the AddTable bit is here just to create a table named fulldesign.csv in case someone wants to test the code who doesn’t have an appropriate table (as was my case).
PennController.ResetPrefix(null) Sequence( "start", "task", "end" ) newTrial("start", newButton("start").print().wait()) newTrial("end", newButton("end").print().wait()) AddTable("fulldesign.csv", `sen,answer,n what's 2+2?,4,1 what's my cat's name?,buffy,2 is this fun?,so-so,3`) Template( "fulldesign.csv" , variable => newTrial( "task" , newVar("attempt").global() .test.is(3).failure( // beginning of Var test newText("warning", "Your guess shouldn't be empty") , newText(variable.sen).print() , newText("input","Enter your guess: ") .after(newTextInput("guess").log("final")) .print() , getVar("attempt").set(0) , newButton("bb", "Continue") .print() .callback( getTextInput("guess").test.text(variable.answer) .failure( getTextInput("guess").test.text("") .success(getText("warning").print()) .failure( getVar("attempt").set( v => v+1 ).test.is(3) .success( getButton("bb").disable(), getButton("next").print() ) ) ) .success( getButton("next").click() ) ) , newButton("next", "Sorry, you failed 3 times") .wait() // end of Var test ) ) .log( "ParticipantID", GetURLParameter("id") ) .log("trial", variable.n) )
Let me know if you have any questions
Jeremy