# Other narrative features (/start/other-narrative-features)



<Accordions>
  <Accordion title="Managing the end of the game" id="managing-the-end-of-the-game">
    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 `steps` are executed.
    * The game has no end; if all steps are completed, another `label` will be started or the player will have to interact with an interface that can potentially start another `label`.
    * 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`](/jsdoc/pixi-vn/index/namespaces/Game/functions/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:

    ```ts title="main.ts"
    import { Game } from "@drincs/pixi-vn";

    Game.onEnd(async (props) => {
        props.navigate("/end");
    });
    ```

    If your game has no end and should restart or loop:

    ```ts title="content/labels/start.label.ts"
    export const startLabel = newLabel("start", () => {
        return [
            // ...
        ];
    });
    ```

    ```ts title="main.ts"
    import { Game } from "@drincs/pixi-vn";

    Game.onEnd(async (props) => {
        narration.call(startLabel, props);
    });
    ```
  </Accordion>

  <Accordion title="Random number generation" id="random-number-generation">
    Pixi’VN includes a built-in function to generate random numbers, use [`narration.getRandomNumber`](/jsdoc/pixi-vn/index/interfaces/NarrationManagerInterface#getrandomnumber).
  </Accordion>

  <Accordion title="Check if the label has already been completed" id="check-if-the-label-has-already-been-completed">
    To check if a `label` has already been completed, use the [`narration.queries.isLabelAlreadyCompleted`](/jsdoc/pixi-vn/index/interfaces/NarrationQueriesInterface#islabelalreadycompleted) function.

    ```typescript
    const isLabelCompleted = narration.queries.isLabelAlreadyCompleted(startLabel);
    const isLabelCompleted = narration.queries.isLabelAlreadyCompleted("labelid");
    ```
  </Accordion>

  <Accordion title="Check if current step has already been opened" id="check-if-current-step-is-already-been-opened">
    To check if the current `step` has already been opened, use [`narration.queries.isCurrentStepAlreadyOpened`](/jsdoc/pixi-vn/index/interfaces/NarrationQueriesInterface#iscurrentstepalreadyopened).

    ```typescript
    const isCurrentStepOpened = narration.queries.isCurrentStepAlreadyOpened;
    ```
  </Accordion>

  <Accordion title="Counter of execution times of the current step" id="counter-of-execution-times-of-the-current-step">
    To get the execution count for the current `step`, use [`narration.currentStepTimesCounter`](/jsdoc/pixi-vn/index/interfaces/NarrationManagerInterface#currentsteptimescounter). &#x2A;*Important:** The counter is only incremented if [`narration.currentStepTimesCounter`](/jsdoc/pixi-vn/index/interfaces/NarrationManagerInterface#currentsteptimescounter) is executed.

    ```ts title="content/labels/start.label.ts"
    export const label = newLabel("id", () => {
        if (narration.currentStepTimesCounter === 0) {
            // ✅ will be incremented
            // ...
        } else {
            // ...
        }
    });
    ```

    ```ts title="content/labels/start.label.ts"
    export const label = newLabel("id", () => {
        if (narration.currentStepTimesCounter === 0) {
            // ✅ will be incremented
            // ...
        } else if (narration.currentStepTimesCounter === 1) {
            // ✅ Not incremented again in this step
            // ...
        }
    });
    ```

    ```ts title="content/labels/start.label.ts"
    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`](/jsdoc/pixi-vn/index/interfaces/NarrationManagerInterface#currentsteptimescounter) to `0`.

    ```ts
    narration.currentStepTimesCounter = 0;
    ```
  </Accordion>
</Accordions>
