Script Branch

Is current?: 
Yes

Sometimes the researcher will want to branch based on more than the random criteria that a group branch can offer.  For these situations, the script branch is your best option.  It can order tasks in virtually any way that the researcher could desire.  The script branch is declared in the <Definitions> section of the experiment file, unlike group branches.  In the <Map> section, you just need <Branch id="myBranchId" type="script" />   to call the branch.   Below is an example that presents different tasks based on how the participant answered an earlier survey.  The exp file posed below uses files from the sample study at http://peoplescience.org/node/106.

 

    <Branch id="dependency" type="script">
        //An array of the possible answers to the variable that we are going to read
        String[] values = {"1", "2", "3"}; 

     
        dropdown = get("dropdown"); //"dropdown" is the task id in the <definitions> section.  Responses in the dropdown task will determine which tasks the branch shows

        //If the value of dditem1 in task "dropdown" is "1","2",or "3" then this will give tasks "checkbox" and "radiogrid". Otherwise it will give task "radiobutton"
        if (Arrays.asList(values).contains(dropdown.results{"dditem1"})) {
        task = get("checkbox");
        task.setParent(get("dependency"));  //change "dependency" to whatever you name your script branch
        children.add(task);
        task2 = get("radiogrid");
        task.setParent(get("dependency"));
        children.add(task2);
        return task;
        }
      else
      {
       task = get("radiobutton");
        task.setParent(get("dependency"));
        children.add(task);
        return task;
      
      }  
</Branch>