Other narrative features
Covers additional narrative features in Pixi’VN, including end-of-game handling, error management, and random number generation.
When all steps of all labels are executed, the game will stop. The developer is responsible for handling the end of the game, as visual novels can have different ending strategies:
- The game ends when all
stepsare executed. - The game has no end; if all steps are completed, another
labelwill be started or the player will have to interact with an interface that can potentially start anotherlabel. - The game ends when the player reaches a specific point, such as due to game over.
To manage the end of the game, set Game.onEnd. This function is called when the game ends and has the same signature as a step.
For example, to end the game and navigate to an end screen:
import { Game } from "@drincs/pixi-vn";
Game.onEnd(async (props) => {
props.navigate("/end");
});If your game has no end and should restart or loop:
export const startLabel = newLabel("start", () => {
return [
// ...
];
});import { Game } from "@drincs/pixi-vn";
Game.onEnd(async (props) => {
narration.call(startLabel, props);
});Pixi’VN includes a built-in function to generate random numbers, use narration.getRandomNumber.
To check if a label has already been completed, use the narration.queries.isLabelAlreadyCompleted function.
const isLabelCompleted = narration.queries.isLabelAlreadyCompleted(startLabel);
const isLabelCompleted = narration.queries.isLabelAlreadyCompleted("labelid");To check if the current step has already been opened, use narration.queries.isCurrentStepAlreadyOpened.
const isCurrentStepOpened = narration.queries.isCurrentStepAlreadyOpened;To get the execution count for the current step, use narration.currentStepTimesCounter. Important: The counter is only incremented if narration.currentStepTimesCounter is executed.
export const label = newLabel("id", () => {
if (narration.currentStepTimesCounter === 0) {
// ✅ will be incremented
// ...
} else {
// ...
}
});export const label = newLabel("id", () => {
if (narration.currentStepTimesCounter === 0) {
// ✅ will be incremented
// ...
} else if (narration.currentStepTimesCounter === 1) {
// ✅ Not incremented again in this step
// ...
}
});export const label = newLabel("id", () => {
if (flag) {
if (narration.currentStepTimesCounter === 1) {
// ❌ Only incremented if "flag" is true
// ...
}
}
});To reset the execution counter for the current step, set narration.currentStepTimesCounter to 0.
narration.currentStepTimesCounter = 0;