Verse Library verse

01 Device

Runs a repeating check every second. Controls game state and termination logic.

verse-library/3-creating-the-game-loop/01-device.verse

# We are making a Pizza Chase game loop.
# This script will watch for the player to win.

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Native }

# This is our main device. It holds the code.
# Think of it as the "Game Manager" box.
pizza_chase_device := class(creative_device):

    # This variable tracks if the game is over.
    # It starts as false (not over).
    # 'var' means we can change it later.
    var IsGameOver : logic = false

    # This is the function that runs when the game starts.
    # 'override' means we are changing the default start behavior.
    # 'suspends' means this code can pause and wait.
    OnBegin<override>()<suspends> : void =
        # Run the main loop function.
        # This will run forever until the game ends.
        RunGameLoop()

    # This is our Game Loop function.
    # It runs in a circle until IsGameOver is true.
    RunGameLoop()<suspends> : void =
        # We use a 'loop' with an early exit.
        # 'loop' means: "Keep doing this forever."
        # 'if' with 'break' means: "Stop if the game is over."

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

    Sign in to vote, comment, or suggest an edit. Sign in