Sample game
Comparison operators
Operator | Description |
is | is equal? |
is not | is different from? |
> | is bigger? |
>= | is bigger or equal? |
< | is smaller? |
<= | is smaller or equal? |
See more in documentation:
- comparison operators – type number
- comparison operators – type string
- comparison operators – type boolean
The if-elseif-else instructions
(if: )
Example 1
Depending on whether the gate is closed or opened (true/false), you can see a hidden message. The value of the $gate_closed
variable may be changed in any slip or in any particular location in a particular fragment of the story (it does not have to change its value at the top of the slip – it can be done between the paragraphs of the text).
(set: $gate_closed to true)
You try to open the gate...
(if: $gate_closed is true)[- unfortunately it is closed! First, you need to get the key.]
Result 1
![Result Result: You try to open the gate... [- unfortunately it is closed! First, you need to get the key.](https://accessible.gameofgdansk.eu/wp-content/uploads/2021/09/example-1-result-5-1024x143.png)
Example 2
If you use a lot of variables, IF instructions, etc. to increase the clarity of the code (a possibility of using whitespace characters, such as ENTER), use { }
characters and code indentation. It will allow you to avoid awkward and unexpected empty space on your slips.
(set: $tip to 1)
You try to open the gate... unfortunately, it is closed!
{
(if: $tip is 1)[maybe I should look for the key in my pocket?]
(if: $tip is 2)[maybe I should check under the flowerpot?]
(if: $tip is 3)[it seems you need to find another way!]
}
Result 2
![Result Result: You try to open the gate... unfortunately, it is closed! maybe I should look for the key in my pocket?](https://accessible.gameofgdansk.eu/wp-content/uploads/2021/09/example-2-result-4-1024x172.png)
See more in documentation
(if: )(else: )
Example 3
(set: $key_found to false)
You try to open the gate...
{
(if: $key_found is true)[you open the gate with the key you have found and you enter the courtyard.]
(else:)[- unfortunately, it is closed! First, you need to get the key.]
}
You can save the IF instruction in its shorter version (if: $key_found)[...]
because the $key_found variable shall take true or false – it does not have to be additionally compared using the is operator.
Result 3
![Result. Result: You try to open the gate... - unfortunately, it is closed! First, you need to get the key.](https://accessible.gameofgdansk.eu/wp-content/uploads/2021/09/example-3-result-2-1024x154.png)
See more in documentation
(if: )(else-if: )(else: )
Example 4
(set: $points to 10)
SUMMING UP: you have got $points points.
{
(if: $points >= 15)[Well done!]
(else-if: $points is 0)[Bad luck!]
(else:)[Not bad! It will be even better next time.]
}
Result 4
![Result Result: SUMMING UP: you have got 10 points. Not bad! It will be even better next time.](https://accessible.gameofgdansk.eu/wp-content/uploads/2021/09/example-4-result-1.png)
See more in documentation
The IF instruction, links and variables
If the gate is closed (true), you will see a text with a link to the “key” slip, otherwise (false) you will see a text with a link to the “courtyard” slip. You can fully decide which links will be visible for players and which links will stay hidden.
Example
(set: $gate_closed to false)
(set: $congratulations to "You’ve made it!")
You try to open the gate...
{
(if: $gate_closed is true)[First, you need to get the [[key]].]
(else:)[$congratulations You can go to the [[courtyard]].]
}
An editor view
![Twine - View from the editor. Twine - View from the editor. The start card is connected with the key and courtyard cards.](https://accessible.gameofgdansk.eu/wp-content/uploads/2021/09/example-2-editor-2.png)
Result
![Result Result: You try open the gate... You`ve made it! You can go to the courtyard.](https://accessible.gameofgdansk.eu/wp-content/uploads/2021/09/example-5-result-1024x155.png)
The IF and (display: )
instruction
The (display: )
macro allows you to display the content of a particular (already existing) slip on another slip. You can also see another example of applying that macro in the tutorial part referring to randomness.
Example
(set: $action to 2)
You enter the courtyard.
{
(if: $action is 1)[(display: "action-1")]
(else-if: $action is 2)[(display: "action-2")]
(else-if: $action is 3)[(display: "action-3")]
(else:)[However, there is nobody there.]
}
An editor view
![Twine - An editor view. Twine - View from the editor. None of the cards are linked by arrows. There are cards on the graphic: start, action 1, 2 and 3.](https://accessible.gameofgdansk.eu/wp-content/uploads/2021/09/example-3-editor-2.png)
Result
![Result. Result: You enter the courtyard. Action 2.](https://accessible.gameofgdansk.eu/wp-content/uploads/2021/09/example-6-result-2-1024x201.png)
Logical operators
Operator | Description |
and | logical conjunction |
or | logical disjunction |
not | logical negation |
Logical conjunction and
The result of the and
(logical conjunction) operation is the True value if and only if the value of both arguments is True.
Argument 1 | Argument 2 | Result |
True | True | True |
True | False | False |
False | True | False |
False | False | False |
Logical disjunction or
The result of the or
(logical disjunction) operation is the True if the value of at least one argument is True. The False value occurs if and only if the value of both arguments is False.
Argument 1 | Argument 2 | Result |
True | True | True |
True | False | True |
False | True | True |
False | False | False |
Logical negation not
The result of the not
operation is the opposite value of the argument.
Argument | Result |
True | False |
False | True |
Example
(set: $night to false)
(set: $flashlight_on to false)
It is (if: $night)[night](else:)[day].
There is an (if: $flashlight_on)[on](else:)[off] flashlight.
{
(if: $night and $flashlight_on)[You notice some strange symbols on the wall. It might be some kind of a password...]
(else-if: not $night and $flashlight_on)[Turning on your flashlight is not a good idea.]
(else-if: $night and not $flashlight_on)[It would be a good idea to turn on your flashlight. It’s very dark in here.]
(else:)[You should wait until the evening and turn on your flashlight to see whether there are any tips hidden in here.]
}
Result
![Result Result: It is day. There is an off flashlight. You should wait until the evening and turn on your flashlight to see whether there are any tips hidden in here.](https://accessible.gameofgdansk.eu/wp-content/uploads/2021/09/example-7-result-1-1024x303.png)