PennController for IBEX › Forums › Support › Update a var only after button click
- This topic has 1 reply, 2 voices, and was last updated 1 year, 2 months ago by Jeremy.
-
AuthorPosts
-
July 24, 2023 at 2:36 am #10773Larissa_CuryParticipant
Hi. I’m redoing an experiment. In this version, user has to click on buttons (ranging from number 0 to 9), which will store their answer, and then this answer will be evaluated.
Ex: user clicks on ‘1″ and “5” and “9”, his answer is 159 (as a string)I guess I was able to adapt the remaining parts of the old code, but I cannot make it store a variable ONLY IF a button is clicked. I cannot put “wait” on all buttons because user may skip some. I tried to change the buttons to a selector but I couldn’t as well. The idea is: user will have to click on the buttons based on a sequence of number’s they’ll hear and then I’ll check if their answer is right.
Experiment is here: https://farm.pcibex.net/r/DwkmNa/
The post where Jeremy’s helped me with the logic is here: https://www.pcibex.net/forums/topic/get-the-previous-row-of-a-column/I tried MANY things so far. I tried to add a
.success
totest.clicked()
but it didn’t work.Template("stimuliNew.csv", row => newTrial("sequence-"+row.lenNumeric, newVar("lastLen",0).global() // We'll set this to lenNumeric at the end of the experiment , newVar("errorCount",0).global() // We'll update this after the key press , // Create new variable 'answer' newVar("answer",'').global() , newButton("testA", "BUTTON 5!") // 5 .print() , getVar("answer").set(v=>v+'5') // 5 , newButton("testB", "BUTTON 9!") // 9 .print() , getVar("answer").set(v=>v+'9') // 9 , newButton("testc", "BUTTON 3!") // 3 .print() , getVar("answer").set(v=>v+'3') // 3 , newButton("testd", "BUTTON 6!") // 6 .print() , getVar("answer").set(v=>v+'6') // 6 , newButton("testOK", "OK!") .print() .wait() , newText("printFirstKey", "") /// just to see the variable .text( getVar("answer") ).print().center() , getVar("answer").test.is(row.keysBackClean) .success( newText("right","Correto! ✅").center().print() , getVar("errorCount").set(0) // Correct: reset the value to 0 , getVar("answer").set(0) // Correct: reset the value to 0 ) .failure( newText("Incorrect").center().print() , // Increment the value by 1, and check if it is equal to 2 getVar("errorCount").set(v=>v+1).test.is(2).success( getVar("lastLen").test.is(row.lenNumeric) .success( newText("2 errors in a row for a sequence of the same length!").center().print() , jump("end") // The next trial will be the one labeled "end" ) .failure( getVar("errorCount").set(1) /* set to 1 if previous length was different */ ) ) ) , getVar("lastLen").set(row.lenNumeric) , newTimer("wait-success",1000).start().wait() ) );
July 24, 2023 at 2:38 am #10785JeremyKeymasterThis issue was reported as resolved in a private email exchange, through the use of the
callback
commandJeremy
-
AuthorPosts
- You must be logged in to reply to this topic.