Arithmetic logic
You can read more about logic and variables in ink on the official documentation.
ink is fully-featured in terms of arithmetic and logic. Any line prefixed with ~ is treated as a logic line rather than story text, which is how you perform calculations and assignments without printing anything to the screen.
Arithmetic operators
ink supports the following arithmetic operators:
| Operator | Description |
|---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% / mod | Modulo (remainder after integer division) |
~ x = (x * x) - (y * y) + c
~ y = 2 * x * y
~ remainder = 10 mod 3Implicit numerical types
Results of operations are typed based on the type of the inputs. In particular, integer division returns an integer, while floating-point division returns a float:
~ x = 2 / 3 // x is 0 (integer)
~ y = 7 / 3 // y is 2 (integer)
~ z = 1.2 / 0.5 // z is 2.4 (float)Comparison and logical operators
The following operators are available for building conditions:
| Operator | Description |
|---|---|
== | Equal to |
!= | Not equal to |
> | Greater than |
\< | Less than |
>= | Greater than or equal to |
\<= | Less than or equal to |
&& / and | Logical AND |
|| / or | Logical OR |
! / not | Logical NOT |
Conditions are written inline inside { } braces:
{ x == 1.2 }
{ x / 2 > 4 }
{ y - 1 <= x * x }String queries
ink supports three basic string operations:
{ "Yes, please." == "Yes, please." } // equality
{ "No, thank you." != "Yes, please." } // inequality
{ "Yes, please" ? "ease" } // substring / contains