Reply To: Proceeding to the next trial based on different conditions

PennController for IBEX Forums Support Proceeding to the next trial based on different conditions Reply To: Proceeding to the next trial based on different conditions

#7778
Jeremy
Keymaster

Hi Noelia,

PennController commands are linearly executed in a top-down fashion. In your code, once PennController reaches newTimer("hurry", 1000).start(), it starts a 1s timer and immediately moves on to the next command, which is getTimer("hurry").test.ended().success(newText("lento", "¡Muy lento!").print(), getTextInput("rta_p1")). Because you just started the timer, of course the test will fail, so you will never see the Text element named “lento” printed on the page

Use a callback command to tell PennController to execute commands not linearly, but instead upon the occurrence of the relevant event associated with the type of element on which you use callback. And if you want the participant to click “Próxima” to move on to the next trial after the timer has elapsed, just add your Timer element’s test as a disjunct (or) in the Button element’s wait:

newTimer("hurry", 60000)
  .callback(
    clear() // remove all elements from the page
    ,
    newText("lento", "¡Muy lento!").print() // print your message
    ,
    getButton("prox").print() // re-print the button, below the message
  )
  .start()
,
newButton("prox", "Próxima")
    .css({margin: "1em", "font-size": "medium"})
    .color("blue")
    .center()
    .print()
    .wait(
      getTimer("hurry").test.ended().or( // validate click if the timer has elapsed...
        getTextInput("rta_p1")           
          .test.text(/^\s*\S+(?:\s+\S+)+\s*$/)  // ... or if there are at least two words in the box
          .failure(
            newText("Es necesario completar el recuadro con más de una palabra para pasar a la próxima oración")
              .center()
              .color("red")
              .print()
          )
      )
    )

Jeremy