PennController for IBEX › Forums › Support › Using if statements during a trial › Reply To: Using if statements during a trial
I’m sorry, I went too fast when posting my answer, here is a revised version of the code:
newTrial( "experiment" , newText ("FullText", row.FullText), newButton("FTButton1","Proceed to next Trial"), newButton("FTButton2","Proceed to Comprehension Question"), newText("CompQ",row.CompQ), newButton("CQButton","Placeholder, just click to answer"), getText("FullText").print(), ( row.CompYN=="Y" ? [ getButton("FTButton2") .print() .wait() .remove("FTButton2","FullText"), getText("CompQ") .print(), getButton("CQButton") .print() .wait() .remove("CompQ","CQButton") ] : [ getButton("FTButton1") .print() .wait() .remove("FTButton1","FullText") ] ) ) //closes newTrial
Besides the lack of double-quotes around Y, the problem was that each comma-separated block of commands represents an object, but the ( test ? success : failure ) structure allows only one object in success and failure. There technically were three objects in the success part of the original code, so the first two were ignored. The solution I just proposed is to package the three objects into a single array: because newTrial treats commands packaged in an array the same way as direct series of commands, you still get the intended result.