LogoPixi’VN

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:

OperatorDescription
+Addition
-Subtraction
*Multiplication
/Division
% / modModulo (remainder after integer division)
file_type_ink
ink
~ x = (x * x) - (y * y) + c
~ y = 2 * x * y
~ remainder = 10 mod 3

Implicit 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:

file_type_ink
ink
~ 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:

OperatorDescription
==Equal to
!=Not equal to
>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to
&& / andLogical AND
|| / orLogical OR
! / notLogical NOT

Conditions are written inline inside { } braces:

file_type_ink
ink
{ x == 1.2 }
{ x / 2 > 4 }
{ y - 1 <= x * x }

String queries

ink supports three basic string operations:

file_type_ink
ink
{ "Yes, please." == "Yes, please." }   // equality
{ "No, thank you." != "Yes, please." } // inequality
{ "Yes, please" ? "ease" }             // substring / contains

Conditional blocks (if / else)

Other features

On this page