# This is a comment! Verse ignores lines starting with #. # We are making a "Snack Station" using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } using { /Verse.org/Random } # 1. Define our "World" # In Verse, every island script is a creative_device. We need to tell Verse # which devices we are working with by declaring them as editable fields. # Replace "snack_world" with whatever name you like for your device class. snack_world := class(creative_device): # 2. Define the Devices # We need to link our Verse script to the physical devices in the level. # "@editable" lets you assign the actual placed device in the UEFN editor. # "button_device" is the button you placed. "granter_device" gives out loot. @editable button_device : button_device = button_device{} @editable granter_device : item_granter_device = item_granter_device{} # 3. OnBegin runs once when the game starts. # We use it to subscribe to the button's InteractedWithEvent so our # handler fires every time a player presses the button. OnBegin() : void = button_device.InteractedWithEvent.Subscribe(OnButtonPressed) # 4. The Event: "When Player Hits Button" # This function runs automatically when someone presses the button. # "InteractedWithEvent" is the real event on button_device; it passes # the agent (player) who triggered it. OnButtonPressed(Agent : agent) : void = # 5. Pick a Random Produce Item # The item_granter_device is pre-configured in the editor with one # produce item per granter. We use an array of granters — one for # each produce type — and pick one at random. # Here we use a single granter that you configure in the editor, # and we randomise whether the player receives the grant (see # the Challenge section below for the 1-in-4 variant). # # Because item_granter_device.GrantItem() needs a player, we first # cast the agent to player. The cast is failable, so we use 'if'. if (Player := player[Agent]): # GetRandomInt(Low, High) returns an integer in [Low, High]. # We have 7 produce granters indexed 0-6; with a single # configured granter we always grant index 0. # note: swap 'granter_device' for an array element if you place # 7 separate item_granter_devices, one per produce type. granter_device.GrantItem(Player) # 6. Optional: Tell the player what they got # We can send a chat message or show a text popup. # For now, let's just keep it simple.