3. Passing data between elements

In addition to setting up flow links, we also need to be able to pass data around between elements. The numberguess game uses a game ID that is used to identify every game that is played. We want to pass this ID around when a game is active. This makes it possible for all the elements to know which game they should work with. Data links are used for this purpose, and their definition is very similar to flow links.

3.1. Defining inputs and outputs

In order to be able to pass input variables to and from an element you need to define inputs and outputs for those variables. To do that, you use input and output tags in the element declaration. After adding the input and output tags to the Guess element declaration, the result is:

Example 3.4. Defining inputs and outputs

<element implementation="tutorial.numberguess.Guess">
  <input name="gameid"/>

  <exit name="start"/>
  <exit name="success"/>

  <output name="gameid"/>
</element>

3.2. Creating the data link

To actually connect the output of one element to the input of another, a data link must be created. An example from the number guess game is the link from the "gameid" output of the Guess element that is connected to the "gameid" input of the Start element:

<datalink srcoutput="gameid" destid="Start" destinput="gameid"/>

After adding datalinks to the example from above, we would get the following:

Example 3.5. Adding data links to the guess element

<site>
  <element id="Guess" file="guess.xml" url="guess">
    <flowlink srcexit="start" destid="Start"/>
    <datalink srcoutput="gameid" destid="Start" destinput="gameid"/>

    <flowlink srcexit="success" destid="Success"/>
    <datalink srcoutput="gameid" destid="Success" destinput="gameid"/>
  </element>
</site>

Note that the output name doesn't have to be the same as the input name, since you provide them both to the datalink tag.