Verse Library verse

01 Device

Tracks lap progress, checkpoints, and per-agent race state using trigger subscriptions and parallel maps.

verse-library/creating-rocket-racing-islands-in-unreal-editor-for-fortnite/01-device.verse

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

# Represents simplified race-progress logic for illustration purposes.
# RR devices handle this automatically in UEFN; this shows the concept in real Verse syntax.
race_progress_manager := class(creative_device):

    # Bind these in the UEFN Details panel to your placed RR devices.
    @editable StartFinishLine : trigger_device = trigger_device{}
    @editable Checkpoints : []trigger_device = array{}

    # Per-agent state tracked in parallel maps.
    var AgentLap : [agent]int = map{}
    var AgentLastCheckpoint : [agent]int = map{}
    var AgentLapStartTime : [agent]float = map{}

    OnBegin<override>()<suspends> : void =
        # Wire the start/finish trigger.
        StartFinishLine.TriggeredEvent.Subscribe(OnStartFinishCrossed)

        # Wire every checkpoint trigger, capturing its index.
        for (Index -> CP : Checkpoints):
            CP.TriggeredEvent.Subscribe(
                # note: spawn a task per checkpoint to handle the subscription with the captured index.
                agent => { spawn { OnCheckpointCrossedAsync(agent, Index) } }
            )

    OnCheckpointCrossedAsync(Agent : agent, Index : int)<suspends> : void =
        OnCheckpointCrossed(Agent, Index)

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