help logoLON-CAPA Help


To create difference versions of Bridge Tasks for each student, parts of the questions are defined using variables. Each variable contains multiple instances of possible values and LON-CAPA randomly selects an instance to give to the student.

All variables are placed inside a Setup element. Each setup element has an id attribute which contains the name of the variable. The possible instances or values of those variables are placed inside the setup element inside an Instance tag. Each Instance element has two mandatory attributes, the OptionalRequired attribute which should be set to 0, and the unique id of that instance. The value of the id attribute can be any text as long as it is unique throughout the document.

The actual data of the instance is placed inside InstanceText tags. Currently the instance data is created with a loncapa/perl script. In this script the parameters of the variable are set. The syntax to set the parameter of a variable is '$variableName {fieldname} = "fieldValues"'. The variable name is taken from the attribute id from the Setup element, the field name is the name of the parameter the author sets, and the fieldValue is simply the value of the field. The first parameter that must be set is the instance field, with the value being an identifier of the instance.

The example below shows a portion of the bridge task XML file. This portion should be placed inside the task element :Lines between < !- and - > or /* and */ are comments and should not be typed into the editor.

<!-- Create a variable named entity Subject  -->
<Setup id="entitySubject">

<!-- The first instance. With id instanceHarry -->
<Instance OptionalRequired="0" id="instanceHarry">

<!-- The parameters for this instance -->
<InstanceText>
	<script type='loncapa/perl'>
		/* The first line must be the instance id */
		$entitySubject{instance} = "instanceHarry";
		/* The two parameters. Personname = Harry and place=zoo */	
		$entitySubject{personname} = "Harry";	
		$entitySubject{place} = "zoo";	
	</script>

</InstanceText>
</Instance>
<!--End of instanceHarry-->

<!-- The second instance. With id instanceBetty -->
<Instance OptionalRequired="0" id="instanceBetty">

<!-- The parameters for this instance -->
<InstanceText>
	<script type='loncapa/perl'>
		/* The first line must be the instance id */
		$entitySubject{instance} = "instanceBetty";	
		/* The two parameters. Personname = Betty and place=park */	$entitySubject{personname} = "Betty";	
		$entitySubject{place} = "park";	
	</script>
</InstanceText>
</Instance>
<!--End of instanceBetty-->

</Setup>

The example above describes a variable question. It has two different possible values for the entity "subject", Harry and zoo or Betty and park. Variables can be placed inside the questions by using the variable name and field name. The first line < Setup id="entitySubject" > creates a variable named entitySubject (based on the id attribute of this line).

The first instance of this variable is shown from lines 2 to 10. Line two < Instance OptionalRequired="0" id="instanceHarry" > marks the beginning of the instance element named instanceHarry (based on the id attribute). The OptionalRequired is given a value of 0. Lines 3-9 determine the actual value of this variable. Lines 3 and 4 must be typed as shown. Lines 5-7 define the instance properties, which must be of the form $ < variable_name > { < property_name > } = < value > . The first line of the property must be the instance property (see line 5 of example), with the value being the id of the instance. Other lines (6-7) can be used for any attributes you wish to define. The closing < /script > , < /InstanceText > and < /Instance > tags must be typed as shown.

Line 12-21 shows the second instance with the same rules as the first instance. Line 23 < /Setup > gives the closing Setup tag which must be as shown.. The example of the usage of this variable inside the question is this text:

This is a test question. $entitySubject{personname} went to the $entitySubject{place}. .

The LON-CAPA engine will replace any instance of $ < variable_name > ( < property_name > ) with the correct value, depending on the randomly chosen instance.

Based on this code, two different questions are possible:

  1. This is a test question. Harry went to the zoo

  2. This is a test question. Betty went to the park