Altre caratteristiche narrative
Copre ulteriori funzionalità narrative di Pixi’VN, tra cui la gestione della fine del gioco, la gestione degli errori e la generazione di numeri casuali.
Quando tutti i passaggi di tutte le etichette saranno stati eseguiti, il gioco si fermerà. Lo sviluppatore è responsabile della gestione del finale del gioco, poiché le visual novel possono avere diverse strategie di conclusione:
- Il gioco termina quando tutti gli
stepssono stati eseguiti. - Il gioco non ha fine; se tutti i passaggi vengono completati, verrà avviata un'altra
labeloppure il giocatore dovrà interagire con un'interfaccia che potenzialmente può avviare un'altralabel. - Il gioco termina quando il giocatore raggiunge un punto specifico, ad esempio a causa di game over.
To manage the end of the game, set Game.onEnd. Questa funzione viene chiamata al termine del gioco e ha la stessa firma di un step.
Ad esempio, per terminare il gioco e passare alla schermata finale:
import { Game } from "@drincs/pixi-vn";
Game.onEnd(async (props) => {
props.navigate("/end");
});Se il gioco non ha fine e deve riavviarsi o andare in 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;