Passing Parameters and Values Between Different Scripts in a Batch

Batch Parameters allow you to send input data to a script. The input data could be used, for example, to set a test's difficulty based on performance on a prior test, or incorporate responses from a prior test. For each batch <parameters> defined in the batch file, any <parameters> of the same name defined in the batch's script files will be set to whatever value the batch <parameters> has when the script starts.

Batch Values allow you to get output data from a script. The output data could be used, for example, store performance metrics from one test to be used in configuring a subsequent test. For each batch <values> defined in the batch file, if a test has a <values> with the same name, the batch <values> is set to whatever value the test <values> has when the test script ends.

Thus, data is exchanged between the batch and the scripts it runs by <parameters> and <values> with the same name. If no matching parameters names are found between batch and scripts, no data is exchanged.

Example: Sharing points across scripts

In the following example, a batch element called "example" calls two scripts, "scriptA.iqx" and "scriptB.iqx. Although scriptA and scriptB are different tasks, participants can earn points in each script and get paid for their total points earned in BOTH scripts at the end of scriptB.

ScriptA.iqx needs to have a way to send its total points to scriptB. The points from scriptA.iqx are first saved using batch values. Those values are then passed into scriptB.iqx using batch parameters.

Batch Script

* Here we define the batch parameters *
<parameters>
/ startPoints = 0
</parameters>

* Here we defined the batch values *
<values>
/totalPoints_scriptA = 0
</values>

<batch example>
/ file = "scriptA.iqx"
/ file = "scriptB.iqx"
/ onscriptend = [
    if (batch.example.currentscript == "scriptA.iqx")
    {
        parameters.startPoints = values.totalPoints_scriptA; 
    }
]
</batch>

The batch script defines a value called "totalPoints_scriptA" that captures the points earned in scriptA.iqx. It also defines a parameter called "startPoints" that will be used to pass the points from scriptA.iqx to scriptB.iqx. These are are initialized to zero.

The batch element uses the onscriptend atribute to set the startPoints parameters after scriptA.iqx is finished. Specfically, the code checks to see whether the script that just finished was scrriptA.iqx, and if so, it sets parameters.startPoints = values.totalPoints_scriptA.

Script A

In order get the points from scriptA.iqx, that script must define a value named "totalPoints_scriptA", and it must set this to whatever the total number of points was at the end of the script. The relevant snippets from scriptA.iqx are below:

* Here we define the script value corresponding to the batch value *
<values>
/totalPoints_scriptA = 0
</values>

<trial A>
...
/ ontrialend = [
    if(trial.A.correct) 
    {
        values.totalPoints_scriptA += 10;
    }
]
...
</trial>

Script B

To get points earned from scriptA.iqx, scriptB.iqx defines a parameter called "startPoints". This parameter is set by the batch at the start of the script, and at the beginning of the experiment (onexptbegin attribute), the points for scriptB.iqx are initialized to that parameter value.

* Here we define the script parameter corresponding to the batch parameter *
<parameters>
/ startPoints = 0
</parameters>

<values>
/ totalPoints_scriptB = 0
</values>

<expt B>
...
/ onexptbegin = [
    values.totalPoints_scriptB = parameters.startPoints;
]
...
</expt>