PennController for IBEX › Forums › Support › End experiment between trials
- This topic has 4 replies, 2 voices, and was last updated 3 years, 1 month ago by
marisolmuru.
-
AuthorPosts
-
February 11, 2022 at 10:27 am #7744
marisolmuru
ParticipantHi everyone!
I’m having some issues with my experiment. It’s a letter-digit span task and it needs to end if a participant has three errors in a set. Combing through the recommendations in this forum I was able to write a code that does just that. I created a “trytoend” trial with a “sendresults” command that is linked with a “shouldend” variable that becomes true when three mistakes are made in a trial (this idea works here, in a very simplified version of the experiment: https://farm.pcibex.net/r/PwHRXt/).
The problem is that when I introduced Templates to be able to add all the stimuli to the trials, it broke and it does not work anymore. And I don’t know how to fix it. Here is the script: https://farm.pcibex.net/r/QfspMA/
Extra question: is there a way to disable a particular key in a TextInput element?
Thank you so much in advance,
MarisolFebruary 11, 2022 at 3:42 pm #7745Jeremy
KeymasterHi Marisol,
Your code uses two Var elements to track accuracy: one named “ACCURACY,” which is global, and one named “acc,” which is not. You use another Var element, named “shouldend,” to determine whether the trial labeled “trytoend” should execute its code, which you set according to whether the value of “acc” is greater than 3. Because “acc” is a local Var element, it is set to 0 at the beginning of every trial, and because you only increase it by 1 during a trial (if the answer was incorrect) it can never reach 3, and you Var element “shouldend” is never to to
true
All you need to do is make your Var element named “acc” global (
newVar("acc", 0).global()
) and your code should workThere is no command for the TextInput element that disabled a particular key. You would need to use a javascript function, for example if you want to prevent the participant from typing
s
orS
you could do this:newTextInput("myInput", "").print() , newFunction(()=>setTimeout(()=>document.querySelector("textarea.PennController-myInput").addEventListener("keydown",e=>{ if (!e.key.match(/s/i)) return true; e.preventDefault(); e.stopPropagation(); return false; }),200)).call()
Jeremy
February 14, 2022 at 12:04 pm #7749marisolmuru
ParticipantHi Jeremy!
Thank you so much for you quick response! The problem with making the acc Var global is that I need it to reset to 0 in each trial (or what I call sets). Because I need the experiment to end only when the participant makes three mistakes in a set, not overall. If, for example, the participant makes one mistake in setA, other in setC, and another one in setD I need the experiment to continue. Only when the participant makes three mistakes in the same set then the experiment should end.
Thank you so much in advance!
M.-
This reply was modified 3 years, 1 month ago by
marisolmuru.
February 14, 2022 at 12:38 pm #7752Jeremy
KeymasterHi Marisol,
I am going to keep calling trials those things that you get with
newTrial
, to be consistent with PennController’s terminology and not confuse potential readersIf you track accuracy independently for different sets of trials, why don’t you use different Var elements for each set? Like this:
Template(GetTable("tabla.csv") .filter( "set" , /a/ ) , row => newTrial("setA", newVar("accSetA", 0).global() , // ... getTextInput("intento").test.text(row.correcta) .failure( getVar("accSetA").set(v => v+1)) .log() , getVar("accSetA").test.is(3) .success( getVar("shouldend").set(true)) // ...
Etc.
Jeremy
February 14, 2022 at 12:59 pm #7753marisolmuru
ParticipantHi Jeremy!
I, simply, hadn’t thought about creating different Var elements for each new trial. I did it and now it works perfectly. Thank you so much for your help!
M.
-
This reply was modified 3 years, 1 month ago by
-
AuthorPosts
- You must be logged in to reply to this topic.