Verse Library verse

03 Messages For Collecting The Secret Battery And The

Sets up race logic by subscribing to spawn, timer, and item pickup events.

extracted-snippets/documentation/fortnite/verse-parkour-template-in-unreal-editor-for-fortnite/03-messages-for-collecting-the-secret-battery-and-the.verse

# Source URL: https://dev.epicgames.com/documentation/fortnite/verse-parkour-template-in-unreal-editor-for-fortnite
# Local doc:  epic-docs/documentation/fortnite/verse-parkour-template-in-unreal-editor-for-fortnite.md
# Section:    Messages for collecting the secret battery and the completion message
# Runs when this device_script is started in a running game
OnBegin<override>()<suspends>:void=
    # You can output to the log like this to determine what your script is up to
    Logger.Print("Parkour Race Script Started!")

    # Subscribing to the AgentSpawnedEvent.
    # When the player spawns, the function "HandleAgentSpawned" is called.
    PlayerSpawnDevice.SpawnedEvent.Subscribe(HandleAgentSpawned)
    # Same for the Timer. We subscribe to when it expires
    TimerDevice.FailureEvent.Subscribe(HandleTimerExpired)

    # We go through our array of batteryItemSpawners and for each Item Spawner, we subscribe to the ItemPickupEvent.
    # We do this for each Item Spawner and we don't save the handle like we did for the AgentSpawnedSubscription and TimerExpiredSubscription above
    # You don't have to save the handle, but without it, you won't be able to cancel the subscription so it will fire every time an item is picked up.
    for (BatterySpawner : BatteryItemSpawners):
        BatterySpawner.ItemPickedUpEvent.Subscribe(HandleBatteryPickedUp)

    <# An alternate way to do the for loop above that uses an integer to walk through the array
       for (i:int := 0..BatteryItemSpawners.Length - 1):
            if (Battery := BatteryItemSpawners[i]):
                Battery.ItemPickedUpEvent.Subscribe(HandlebatteryPickedUp) #>

    SecretBatteryItemSpawner.ItemPickedUpEvent.Subscribe(HandleSecretBatteryPickedUp)

Comments

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