End experiment between trials

PennController for IBEX Forums Support End experiment between trials

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #7744
    marisolmuru
    Participant

    Hi 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,
    Marisol

    #7745
    Jeremy
    Keymaster

    Hi 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 work

    There 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 or S 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

    #7749
    marisolmuru
    Participant

    Hi 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 2 years, 2 months ago by marisolmuru.
    #7752
    Jeremy
    Keymaster

    Hi 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 readers

    If 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

    #7753
    marisolmuru
    Participant

    Hi 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.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.