The Ultimate Loot Gobbler: How to Make Verse Listen to You
The Ultimate Loot Gobbler: How to Make Verse Listen to You
So, you’ve built a trap. It’s deadly. It’s efficient. It’s also incredibly boring because it does the exact same thing every single time. You want a trap that deals more damage if the player is low on health, or heals more if they’re in a critical state. You need your code to be flexible. You need parameters.
In this tutorial, we’re going to build a "Chaos Chest." Instead of just giving everyone the same loot, this chest will look at your current health and decide whether to hand you a healing potion, a shield potion, or a weapon—based on what you actually need. We’ll learn how to pass data into functions using parameters and arguments, turning static code into dynamic gameplay.
What You'll Learn
- Parameters: How to define "slots" for data inside a function (like setting up empty loot slots).
- Arguments: The actual data you plug into those slots when you call the function.
- Dynamic Logic: How to use incoming data to change the outcome of your code without writing new functions.
How It Works
Imagine you’re at the Battle Bus. Before you jump, you can’t know exactly what loot you’ll find. But you can set up the rules: "If health is below 50, drop a potion."
In Verse, functions are like vending machines. A simple function is a machine that only sells one specific item, no matter what. A function with parameters is a smart vending machine. It asks you for input before it dispenses the reward.
The Anatomy of a Parameter
When you define a function, you can leave the parentheses empty () if it needs no info. But if you want the function to make a decision based on outside info, you add a parameter.
Think of a parameter like a variable slot in your inventory. You define the slot (e.g., "Health Potion Slot"), but it’s empty until you put something in it.
- Parameter: The name of the slot defined in the function signature. It’s a placeholder.
- Argument: The actual item you put in the slot when you use the function.
Example:
If you have a function HealPlayer(), it heals a fixed amount.
If you have a function HealPlayer(amount : float), amount is the parameter.
When you call HealPlayer(50.0), 50.0 is the argument.
Why This Matters for Scene Graph & UE6
In Unreal Engine 6 (and Verse’s future), everything is an Entity in a Scene Graph. Entities have Components that hold data. Parameters allow your scripts to talk to these components dynamically. Instead of hardcoding a damage value into a script, you pass the weapon’s damage value as an argument. This makes your code reusable across hundreds of different weapons, traps, and props without rewriting the logic every time.
Let's Build It
We are building a Dynamic Loot Dispenser. This script will check a player’s health and return the appropriate item type.
Step 1: The Function with a Parameter
First, we define a function that takes a parameter. This parameter will represent the player's current health.
# Define a function called GetLootForHealth
# It takes one parameter: current_health (a float number)
# It returns a string representing the loot item
GetLootForHealth(current_health : float) : string = |
# We use the parameter 'current_health' inside the function
# If health is low (below 50), you get a potion
if (current_health < 50.0): |
return "Shield_Potion"
# If health is medium (50-80), you get a bandage
else if (current_health <= 80.0): |
return "Bandage"
# If health is high, you get a weapon (because you don't need healing)
else: |
return "Assault_Rifle"
Breakdown:
GetLootForHealth(current_health : float): Here,current_healthis the parameter. It’s a placeholder. Verse doesn’t know what value it is yet.current_health < 50.0: We use that placeholder in our logic.return "Shield_Potion": This is the result.
Step 2: Calling the Function with Arguments
Now, let’s say we have two players: NoobSlayer (who has 20 health) and TankMode (who has 90 health). We call the same function, but we pass different arguments.
# Simulate NoobSlayer's state
noob_health : float = 20.0
noob_loot : string = GetLootForHealth(noob_health)
# Result: noob_loot is "Shield_Potion"
# Simulate TankMode's state
tank_health : float = 90.0
tank_loot : string = GetLootForHealth(tank_health)
# Result: tank_loot is "Assault_Rifle"
Breakdown:
noob_healthis a variable holding20.0.GetLootForHealth(noob_health)passes20.0into the function.20.0is the argument.- The function runs its logic with
current_healthnow equal to20.0.
Step 3: Putting It in a UEFN Device
In UEFN, you’d typically attach this script to a Prop or a Trigger Volume. When a player enters, you grab their health and pass it to the function.
Try It Yourself
Challenge: Modify the GetLootForHealth function to add a third tier. If the player’s health is exactly 100.0 (full health), they should get a Gold Bar instead of a weapon.
Hint: You’ll need to add another else if check specifically for current_health == 100.0. Remember to place it before the final else block, or the full-health player will get a rifle anyway!
Recap
- Parameters are placeholders in a function definition that tell the function what kind of data it expects.
- Arguments are the actual values you pass into the function when you call it.
- By using parameters, you can write one flexible function that behaves differently based on the input, just like a smart vending machine.
References
- https://dev.epicgames.com/documentation/en-us/fortnite/basics-of-writing-code-8-how-input-parameters-and-arguments-work-in-verse
- https://dev.epicgames.com/documentation/en-us/uefn/learn-code-basics-7-practice-time-in-verse
- https://dev.epicgames.com/documentation/en-us/fortnite/basics-of-writing-code-8-practice-time-in-verse
- https://dev.epicgames.com/documentation/en-us/uefn/learn-code-basics-8-input-parameters-arguments-in-verse
- https://dev.epicgames.com/documentation/en-us/uefn/learn-the-basics-of-writing-code-in-verse
Get the complete code — free
You've read the full walkthrough. The complete, copy-paste-ready Verse solution is free for members — sign in to unlock it.
Free with your BrainDead.TV / BrainDeadGuild Discord account. The walkthrough above is always free.
Verse source files
- 01-fragment.verse · fragment
- 02-fragment.verse · fragment
- 03-fragment.verse · fragment
Turn this into a guided course
Add basics-of-writing-code-8-how-input-parameters-and-arguments-work-in-verse to your free study plan — we'll suggest related pages and stitch the lot into one compile-checked, self-guided lesson with worked examples and quizzes.
References
Original tutorial generated by Verse Island from the Verse/UEFN knowledge base, with references to the Epic Games sources above. Code is validated against the knowledge base.