# 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 # Step 3: The 'or' Decision. # We try OutcomeA. If it has a value (Success), we use it. # If OutcomeA is false (Failure), we use OutcomeB. # Since we rolled 0 or 1, one of them *must* succeed. SelectedItem := OutcomeA or OutcomeB # Step 4: Log which item was picked. # (In a real build, you'd call the Granter's "GrantItem" function here.) Log("Player gets: {SelectedItem}") # OnBegin runs automatically when the game session starts. OnBegin() : void = # We don't need to do anything at startup for this demo, # but this is where you'd wire up event subscriptions. Log("LootBox device ready.") }