Syntax - Variables

XIMPEL can keep track of variables during your presentation. In the playlist you can define when and how to change variables. Variables can be used to keep track of scores for example.

playlist.xml

						<?xml version="1.0" encoding="utf-8"?>
						<ximpel>
							<playlist>
								<subject id="subject1">
									<media>
										<youtube id="AI0RTvlm0hw" startTime="301" duration="30">
											<overlay leadsTo="subject2" x="200" y="100" shape="rectangle" width="400px" height="200px" text="Go subject2" fontSize="2em" />
											<overlay leadsTo="subject3" x="700" y="100" shape="rectangle" width="400px" height="200px" text="Go subject3" fontSize="2em" />
										</youtube>
									</media>
								</subject>
								<subject id="subject2">
									<media>
										<youtube id="iNr0efL7Wz8" startTime="100" duration="30">
											<variable id="score1" operation="add" value="100" />
											<variable id="score2" operation="substract" value="50" />
										</youtube>
									</media>
								</subject>
								<subject id="subject3">
									<media>
										<youtube id="iBTIQ--9er0" startTime="120" duration="30">
											<variable id="score1" operation="substract" value="50" />
											<variable id="score2" operation="add" value="75" />
										</youtube>
									</media>
								</subject>
							</playlist>
						</ximpel>
In this example, during the playback of the first subject, the users gets the choice between clicking two overlays. One leads to subject2 and the other leads to subject3. Depending on which subject is chosen, the user will get different points for the score1 and score2 variables.

The <score> alias

The <variable> tag is used to define and modify variables. A common use case for variables is to keep track of scores. For that reason, instead of using the <variable> tag, you can use a <score> tag. The <score> tag is simply an alias for <variable> and has the exact same meaning but is more intuitive when keeping track of scores.

So, this:
<variable id="test" operation="substract" value="5" />
Is exactly the same as:
<score id="test" operation="substract" value="5" />
Both statements define the exact same variable and if you have both of these statements within an overlay tag, then when the overlay is clicked 5 is substracted from the test variable twice.

Changing variables

Variable modifications can be defined in the following places:
  • Within the playlist tag - the score is changed when the playlist starts (initialization of variables)
  • Within a subject - the score is changed when the subject starts
  • Within a media item - the score is changed when the media item starts
  • Within an overlay - the score is changed when that overlay is clicked
  • Within a question - the score is changed when that question is answered correctly

playlist.xml

						<?xml version="1.0" encoding="utf-8"?>
						<ximpel>
						<playlist>
							<score id="scoreA" operation="set" value="0" />

							<subject id="subject1">
								<score id="scoreA" operation="add" value="5" />
								
								<media>
									<youtube id="AI0RTvlm0hw">
										<score id="scoreA" operation="multiply" value="3" />
										
										<overlay leadsTo="subject2" backgroundColor="red">
											<score id="scoreA" operation="substract" value="2" />
										</overlay>
										
										<question>
										    <score id="scoreA" operation="multiply" value="2" />
										    Is a cow an animal?
										</question>
									</youtube>
								</media>
							</subject>

							<subject id="subject2">
						        <media>
						            <youtube id="J_x-dIA7oeE" />
						        </media>
							</subject>

						</playlist>
						</ximpel>
  • When the playlist starts the scoreA variable is set to 0.
  • When subject1 starts, the variable is increased with 5.
  • Then the youtube video will start and the variable is multiplied by 3.
  • When the user clicks the overlay, 2 is substracted from the variable.
  • When the question is answered correctly the variable is multiplied by 2.

Available variable operations

As described above you can change variables/scores by providing a variable id an operation and a value. XIMPEL supports the operations add, substract, multiply, divide, power and set.

						<variable id="scoreA" operation="add" value="5" />
						<variable id="scoreA" operation="substract" value="5" />
						<variable id="scoreA" operation="multiply" value="5" />
						<variable id="scoreA" operation="divide" value="5" />
						<variable id="scoreA" operation="power" value="5" />
						<variable id="scoreA" operation="set" value="5" />
They are pretty self descriptive. For example add adds the specified value to the current variable, set sets the value of the variable to the specified value, power uses the specified value as exponent/power and the current variable value as the base (ie. new_score = current_scorevalue).