Verse Library verse

01 Device

Demonstrates using if-else expressions and failable values to randomly select and determine outcomes.

verse-library/or-right/01-device.verse

# Import the basic Verse tools we need
using { /Verse.org/Simulation }
using { /Fortnite.com/Devices }
using { /UnrealEngine.com/Temporary/Diagnostics }

# This is our "Loot Box" script.
# It's a "creative_device" because it lives on the island and listens for events.
loot_box_device := class(creative_device) {

    # This function picks the loot and announces it.
    # It takes a "agent" (a player-like entity) as input.
    GiveRandomLoot(Agent : agent) : void =
        # Step 1: Roll a virtual die.
        # GetRandomInt(0, 1) gives us either 0 or 1.
        # 0 = Heads, 1 = Tails.
        Roll := GetRandomInt(0, 1)

        # Step 2: Define our two possible outcomes.
        # In Verse, we can create "Failable" values using 'if' expressions.
        # If the condition is true, we "succeed" with a value.
        # If false, we "fail" (the expression has no value).

        # Outcome A: If Roll is 0, we "succeed" with the string "ShieldPotion".
        # If this is true, the value "ShieldPotion" is passed forward.
        # If false, this part "fails" and Verse looks at the 'or' part.
        OutcomeA := if (Roll = 0) then "ShieldPotion" else false

        # Outcome B: If Roll is 1, we succeed with "Bandage".
        # We assume if it wasn't 0, it must be 1, so we give the Bandage.
        OutcomeB := if (Roll = 1) then "Bandage" else false

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