Verse Library verse

04 Messages To Display When A Battery Is Collected

Processes battery pickups, increments the collection counter, checks victory conditions, and triggers appropriate HUD feedback.

extracted-snippets/documentation/en-us/uefn/verse-parkour-template-in-unreal-editor-for-fortnite/04-messages-to-display-when-a-battery-is-collected.verse

# Source URL: https://dev.epicgames.com/documentation/en-us/uefn/verse-parkour-template-in-unreal-editor-for-fortnite
# Local doc:  epic-docs/documentation/en-us/uefn/verse-parkour-template-in-unreal-editor-for-fortnite.md
# Section:    Messages to display when a battery is collected
    # Function that is called when a battery item is picked up from the Item Spawners
    HandleBatteryPickedUp(Agent:agent):void=
        # Increment the number of batteries collected
        set BatteriesCollected = BatteriesCollected + 1
        # This is how you can output the number of batteries to the log. Useful for debugging        
        Logger.Print("Number of batteries picked up: {BatteriesCollected}")

        # Check to see if there are enough batteries collected to the end the game
        if:
            BatteriesCollected >= BatteryItemSpawners.Length
        then:
            # Check to see if we've collected 4 (or more) batteries. If so, we have won, call the EndGame function
            spawn { EndGame(Agent) }
        else:
            # This code runs if the number of batteries is less than 4. Show a Hud Message to spur the player on
            # HUD message is "battery" if only 1 battery is collect. Becomes "batteries" if more than 1 is collected
            if:
                BatteriesCollected = 1
            then:
                HUDMessageBattery.SetText(BatteryCollectedMessage(BatteriesCollected))
                HUDMessageBattery.Show(Agent)
            else:
                HUDMessageBattery.SetText(BatteriesCollectedMessage(BatteriesCollected))
                HUDMessageBattery.Show(Agent)

            # Then we get the next Item Spawner in our array we set up
            # We do this by "indexing" into the array. It is inside the "if" statement to ensure that NextBatterySpawner is referenced correctly

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