The Magic Potion Shop: Making Consumables in Verse
The Magic Potion Shop: Making Consumables in Verse
Do you like collecting treasure? Do you like drinking potions that make you faster? In Fortnite Creative, these items are called consumables. They are special items that disappear after you use them. This tutorial shows you how to code a shop where players can buy magic potions. You will learn how to give items to players using Verse.
What You'll Learn
- What a consumable is (an item you use once).
- How to give an item to a player using code.
- How to make a simple trading system.
- How to use the Scene Graph to connect devices.
How It Works
Think of a consumable like a slice of pizza. Once you eat it, it is gone. It is not part of your permanent collection. It is an item that does a job and then disappears.
In Fortnite Creative, we have many consumables. There are health potions. There are ammo boxes. There are even crafting materials like wood and stone.
We will build a Magic Potion Shop. Here is the plan:
- A player walks near a counter.
- The player presses a button.
- The code checks if the player has enough "coins" (score).
- If they have coins, the code takes the coins away.
- The code gives the player a Health Potion.
This is like a real vending machine. You put money in, and it drops a soda. We will make this happen with Verse.
Let's Build It
We will use two main things:
- A Device to catch the player's action.
- Verse to handle the logic.
First, place a Trigger Volume in your island. This is an invisible box. When a player walks inside, it wakes up. Next, place a Text Button inside that box. This is the button the player will press.
Now, let’s write the Verse code. This code lives in a Script device.
# This script makes a potion shop work.
# We need to talk to the button and the player.
# A "Device" is any object in our game world.
# We use "Event" to wait for something to happen.
Event OnPlayerInteracts(player: Player, button: TextButton):
# Check if the player is the one pressing the button.
# We use "if" to ask a question.
if button.IsPressed(player):
# Check the player's score.
# Score is like a variable that counts points.
# We treat score as "coins" for this shop.
coins := player.GetScore()
# Does the player have 10 coins?
if coins >= 10:
# Take 10 coins away.
# This is like paying for the item.
player.SetScore(coins - 10)
# Give the player a Health Potion.
# We use "Grant" to add an item to their inventory.
# "Health_Potion" is the name of the item.
player.Grant(Health_Potion)
# Tell the player "Thanks!"
# We use "ShowMessage" to talk to them.
player.ShowMessage("You bought a potion!")
else:
# Not enough coins.
player.ShowMessage("You need 10 coins!")
Breaking Down the Code
Let’s look at the important parts.
Event OnPlayerInteracts
This line waits for a player to touch the button. It is like a doorbell. It only rings when someone pushes the button.
player.GetScore()
This gets the current number of points. We are using points as money. If you have 100 points, you have 100 coins.
player.Grant(Health_Potion)
This is the magic line. It puts a Health Potion into the player’s bag. The item is now theirs. They can use it to heal.
player.SetScore(coins - 10)
This subtracts 10 from their score. If they had 100, they now have 90. The cost is paid.
Try It Yourself
Now it is your turn to build!
Challenge: Make a Speed Boost shop.
- Place a new Text Button.
- Change the item in the code from
Health_PotiontoSpeed_Boost. - Change the cost from 10 to 20 coins.
- Change the message to say "Speedy!"
Hint:
Look at the Grant line. Just change the name inside the parentheses. Make sure you also change the number in the if coins >= 10 line to 20.
Recap
You just built a working shop! You learned that:
- Consumables are items that get used up.
- Events listen for player actions like pressing buttons.
- Grant gives items to players.
- Score can be used as a simple currency.
Great job! You are now a Verse coder. Keep building amazing islands.
References
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-consumables-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/fortnite-glossary
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-food-crafting-consumables-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-mechanical-crafting-consumables-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-nature-consumables-in-fortnite-creative
Verse source files
- 01-fragment.verse · fragment
Turn this into a guided course
Add using-consumables-in-fortnite-creative 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.