Reply To: Using if statements during a trial

PennController for IBEX Forums Support Using if statements during a trial Reply To: Using if statements during a trial

#5579
mrhelfrich
Participant

Thank you for the quick reply, unfortunately the code you posted is throwing syntax errors when I copy it over. I am not great at understanding the error messages but it seems like it by default after the test ? error checker only allows one get command. I added parentheses to envelop all of the commands that I wanted to run before the : and this gets rid of the syntax errors but when I run the code it doesn’t execute properly (I also had to change row.CompYN==Y ? to row.CompYN=="Y" ? since it was treating it as an expression. I am not certain but it appears that putting parentheses around the multiple commands only stops the syntax errors and the conditional operator you showed me will only run the last command listed before the colon. I changed the text displayed on the buttons to make it easier to see but it looks like the test itself functions properly but it doesn’t execute all of the code when row.CompYN=="Y" is true.

Here’s the code I have been running that at doesn’t give syntax errors but doesn’t run as expected.

PennController.ResetPrefix(null);
// for the sake of forum posting
AddTable( "IfTable" , 
"TrialNum,FullText,CompYN,CompQ,CompR,CompTF\n"+
"1,Trial 1 does not have a comprehension question.,N,,,\n"+
"2,Trial 2 does have a comprehension question.,Y,Placeholder question for Trial 2 click button to continue no response needed correct answer will be 1 or True.,2,F\n"+
"3,Trial 3 does have a comprehension question.,Y,Placeholder question for Trial 3 click button to continue no response needed correct answer will be 2 or False.,2,F\n"+
"4,Trial 4 does not have a comprehension question.,N,,,\n"+
"5,Trial 5 does have a comprehension question.,Y,Placeholder question for Trial 5 click button to continue no response needed correct answer will be 1 or True.,1,T\n"
);
Template( "IfTable" , row =>
    newTrial( "experiment" ,
        newText ("FullText", row.FullText),
        newButton("FTButton1","Proceed to next Trial"),
        newButton("FTButton2","SHOULD DISPLAY IMMEDIATELY AFTER TRIAL 1 AND 4"),
        newText("CompQ",row.CompQ),
        newButton("CQButton","SHOULD DISPLAY WITH COMPQ TEXT ABOVE"),
        getText("FullText").print(),
            (row.CompYN=="Y" ?  // functions like an if statement based on the specified test, if row.CompYN==Y, then the following code is executed, if not, run code after the colon
              ( // parentheses needed to include multiple commands as part of the 'success' branch of the above test  
                getButton("FTButton2")
                    .print()
                    .wait()
                    .remove("FTButton2","FullText"),
                getText("CompQ")
                    .print(),
                getButton("CQButton")
                    .print()
                    .wait()
                    .remove("CompQ","CQButton")
              ):  // close parentheses and then colon marks the change to the 'failure' branch of the test
        getButton("FTButton1")
            .print()
            .wait()
            .remove("FTButton1","FullText")       
            )  // closes the 'test'
    ) // closes newTrial
)  // closes Template

Thanks again for all of your help,
Max