States Part 2
Randomness
You can use inline functions and state setting before
the if-element to create a certain chance of something happening.
For example:
<number name="chance" value="{random 0, 100}"/>
<if check="[chance] lower 30">
<text>Luckily, the potion wasn't poisoned. You once read that out of 10 potions,
3 are poisoned, so you can call yourself lucky!
</text>
<choice station="back">Back</choice>
</if>
<if check="[is immune to poison]">
<text>The potion contained poison... you're very grateful now
that you're immune to poison!
</text>
<choice station="back">Back</choice>
</if>
<else>
<text>The potion contained poison and you're dead now.
</text>
</else>
This example containted multiple ifs. But there can be no more or less than one else.
(If you're used to programming if-conditions you will note that the second "if" is actually an "else-if".)
Now the [chance] that was used is actually a number, which are explained in more detail later in this tutorial.
Input
To ask for user input, use an input after the text, instead of a normal choice:
<station id="unicorn">
<text>
"Do you know what I am?" she asks you.
<break/>
<emphasis>What do you answer?</emphasis>
</text>
<input station="unicorn answer">OK</input>
<choice station="back">You don't answer and
leave</choice>
</station>
<station id="unicorn answer">
<if check="[qmlInput] = 'unicorn'">
<text>"Oh, you do know me!" she cries.
</text>
<state name="knows unicorn"/>
<choice station="unicorn continue">Continue</choice>
</if>
<else>
<text>"So that's what you take me for?" she sighs.
</text>
<choice station="unicorn continue">Continue</choice>
</else>
</station>
Continue with States Part 3