# LootGoblin.verse
# This script makes a Button dispense a Repair Torch when pressed.
# 1. DEFINE THE VARIABLES (The Inventory)
# 'Available_Torches' is a variable. It's like your ammo counter.
# It starts at 5, meaning the button can be pressed 5 times before it breaks.
Available_Torches := 5
# 2. DEFINE THE FUNCTION (The Action)
# 'Spawn_Torch' is a function. It’s a recipe for what happens when the button is pressed.
# It takes one input: 'Player' (the person who pressed the button).
Spawn_Torch := function(Player: Player):
# Check if we have any torches left (The Inventory Check)
if Available_Torches > 0:
# Decrement the counter.
# 'Available_Torches -= 1' means "Take the current value, subtract 1, and save it back."
# Think of it like using a shield potion: your shield count goes down.
Available_Torches -= 1
# Spawn the Item
# We use the 'Item_Granter' device from the editor.
# In Verse, we need to reference the specific device instance.
# For this example, we assume you placed an 'Item Granter' device
# in the editor and named it 'TorchDispenser'.
# Note: In a real Verse script, you'd typically link the device
# via a 'Device' component or reference. Here is a simplified
# logic flow for educational purposes:
print("Dispensing Repair Torch! Torches left: ", Available_Torches)
Verse Library
verse
01 Fragment
Manages a limited supply of torches, checking stock and decrementing when dispensed.
verse-library/using-portable-consumables-in-fortnite-creative/01-fragment.verse
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.