QML - Create Your Own Adventure

States Part 3

Numbers

You may want to have states you can increment/ decrement. For example, you want to have a world with gold, and the more gold the player collects, the more he can buy. Therefore, you would increase "gold coins" everytime the player finds something, and decrease it everytime the player buys something. Another use for numbers would be to create an RPG like attribute system. (Speed, agility, luck, strength, etc.)

Setting numbers

To set a number, you write:

<if check="not [treasure chest empty]">
    <text>You see a big treasure and stuff yourself with 50 gold coins. </text>
    <state name="treasure chest empty" />
    <number name="gold" value="[gold] + 50" />
    <choice station="closeTreasure">Close treasure chest</choice>
</if>
<else>
    <text>The treasure chest is empty.
    </text>
    <choice station="closeTreasure">Close treasure chest</choice>
</else>

A number that hasn't been handled by your story yet is set to 0. (States are set to false.)

Checking numbers

You check the value similar to how you check states. For example, if you want to test if the player has knocked more than 5 times on a door which nobody answered so far:

<if check="[knocked on door] greater = 5">
    ...
</if>

You can use "=", "greater", "lower", or combinations, like "greater =", or e.g. "not [x] greater = 3".

Numbers are not case-sensitive. If you would have checked for knocked on door instead of Knocked On Door the result would have been the same.

Outputting numbers

To output the number value directly into the text, use the same square brackets you use in checks:

<text>You now have [number gold] gold coins.
</text>

When the text is displayed in the game, the [number gold] you wrote in the XML source would be replaced with the actual numeric value.

For more information (adding numbers, internal numbers, station visits, number limits) refer to the number details.

Strings

Strings are used like numbers. There are various conversion methods (like lower-case formatting) when you output them, and there's various comparisons (like if a string contains a certain word). Strings can add more flexibility and a longer life-span to user input text.

<string name="playerName" value="Joe"/>

For more information, refer to the internal strings table.

Functions

Several functions help convert/ check states. A function is written like the following, using curly brackets:
<if check="{random 1, 6} = 4">

Name Parameters Explanation
random min, max Returns a random number between numbers min and max
states string Returns a list of all names of true states that start with this string. Interesting especially to handle e.g. a player inventory display.
contains string, sub-string Checks if a string contains a sub-string and returns true or false
containsWord sentence, word Checks if a sentence contains a word and returns true or false
verbose number Returns a string containing a verbose represention of the number provided, e.g. 5 is 5th.
lower string Returns a lower-case version of the submitted string
upper string Returns an upper-case version of the submitted string
repeatString string, n Repeats the submitted string n times

Continue with QML Chapters