LogoPixi’VN

临时存储

You can read more about temporary variables in ink on the official documentation.

Sometimes a global variable is unwieldy. ink provides temporary variables for quick, local calculations. Unlike global variables (VAR), a temporary variable is discarded as soon as the story leaves the knot or stitch in which it was defined.

In the ink + Pixi'VN integration, temp variables are equivalent to temporary variables in storage.

定义

This functionality in Javascript/TypeScript corresponds to temporary variables in storage.

Declare a temporary variable with the temp keyword inside a ~ logic line:

file_type_ink
ink
~ temp myTemp = 42

You can use any type that ink supports: integer, floating point, boolean, or string.

file_type_ink
ink
=== near_north_pole ===
    ~ temp number_of_warm_things = 0
    { blanket:
        ~ number_of_warm_things++
    }
    { ear_muffs:
        ~ number_of_warm_things++
    }
    { gloves:
        ~ number_of_warm_things++
    }
    { number_of_warm_things > 2:
        Despite the snow, I felt incorrigibly snug.
    - else:
        That night I was colder than I have ever been.
    }

The variable number_of_warm_things is created when the knot is entered and thrown away when it is left.

设置

This functionality in Javascript/TypeScript corresponds to storage.set.

After the initial declaration you can reassign a temporary variable with the same ~ syntax (without repeating the temp keyword):

file_type_ink
ink
~ temp score = 0
~ score = score + 10
~ score++

获取

To get a temporary variable, use the normal storage.get function.

Inside ink itself, you read a temporary variable exactly the same way as any other variable – by using its name in an expression, inline print, or condition:

file_type_ink
ink
~ temp duration = 3

The duration is: {duration}
{ duration > 2:
    It's a long scene.
- else:
    It's a short scene.
}

On this page