Reply To: How to assign participants to two sessions

PennController for IBEX Forums Support How to assign participants to two sessions Reply To: How to assign participants to two sessions

#6643
Jeremy
Keymaster

Hi Nan,

The whole const/switch part of your code is executed at the very beginning of your experiment, at which point your Var element named day has not been set to the participant’s input yet. What’s tricky is that you do need to run Sequence at the very beginning of your experiment, because the engine won’t accept modifications to the sequence after it has started running the first trial.

You can pass the session number in the URL, and then retrieve it from your script using GetURLParameter. If you’re already using the URL to control which group your participants are assigned, you could have your links end with server.py?withsquare=1&day=1 and do something like this:

const group = Number(GetURLParameter("withsquare"));
const day = Number(GetURLParameter("day"));

switch (day){
  case 1:
    switch(group){
      case 1:
        Sequence( "test",  randomize("experiment") , SendResults() , "bye" );    
        break;
      case 2:
      default:
        Sequence( "test2",  randomize("experiment") , SendResults() , "bye" );    
        break;
    }
    break;
  case 2:
  default:
    switch (group) {
      case 1:
        Sequence( "test2",  randomize("experiment") , SendResults() , "bye" );    
        break;
      case 2:
      default:
        Sequence( "test",  randomize("experiment") , SendResults() , "bye" );    
        break;
    }
    break;
}

If you need to ask your participant to type an ID and/or a day number, I would actually add a statement to the switch checking that day is not set, and in that case execute Sequence("form")—with a trial labeled "form" which should generate a link with the appropriate parameters in the URL. Here’s an example (assuming participant IDs end with a digit and you assign group based on it being odd vs even):

newTrial( "form" ,
  newText("Is this your first or your second session?").print()
  ,
  newScale("day", "1st", "2nd")
    .default("1st")
    .labelsPosition("right")
    .print()
  ,
  newText("Please type in your ID below").print()
  ,
  newTextInput("ID").print()
  ,
  newButton("Submit")
    .print()
    .wait( 
        getTextInput("ID").test.text(/\d/).failure( newText("Please type your ID").print() ) 
    )
  ,
  clear()
  ,
  getTextInput("ID").test.text(/[02468]$/)
    .success(
        getScale("day").test.selected("1st")
          .success( newText("<a href='server.py?withsquare=1&day=1'>Start the experiment</a>").print() )
          .failure( newText("<a href='server.py?withsquare=1&day=2'>Start the experiment</a>").print() )
    )
    .failure(
        getScale("day").test.selected("1st")
          .success( newText("<a href='server.py?withsquare=2&day=1'>Start the experiment</a>").print() )
          .failure( newText("<a href='server.py?withsquare=2&day=2'>Start the experiment</a>").print() )
    )
  ,
  newButton().wait() // Wait until a click on the link refreshes the page
)

Let me know if you have questions

Jeremy