The Art of Taking Things Away: Mastering Decrement in Verse
Tutorial beginner

The Art of Taking Things Away: Mastering Decrement in Verse

Updated beginner

The Art of Taking Things Away: Mastering Decrement in Verse

So you know how to give players loot, points, and lives? Great. But what happens when they die? Or when a trap goes off? Or when you want to make a "survive 60 seconds" timer that actually counts down?

That’s where decrement comes in. It’s the programming equivalent of taking a bite out of an apple, or watching your shield bar drop when a sniper hits you. If Increment is the Battle Bus flying in, Decrement is the Storm closing in.

In this tutorial, we’re going to build a "Health Potion Dispenser" that only gives you one shot. You grab the potion, your health goes up, but the dispenser locks itself forever. Why? Because we’re using decrement to track that single use. Let’s break down how to count backwards without losing your mind.

What You'll Learn

  • What a variable is (and why it’s not just a math class nightmare).
  • How to use the Decrement function to lower values.
  • How to combine Increment and Decrement to create game logic (like health vs. ammo).
  • How to use the Scene Graph to make your code talk to the game world.

How It Works

The Concept: Variables are Just Loot Bags

Imagine a Loot Bag in Fortnite. When it lands, it has a certain amount of items inside. Let’s say it has 3 energy drinks.

  • Variable: This is the Loot Bag itself. It can hold different amounts at different times. When you take a drink, the number inside changes. In Verse, we call this a variable because its value varies.
  • Constant: This is the map layout. The walls don’t move. The storm circle size is set once. In Verse, a constant is a value that never changes once the game starts.

Increment vs. Decrement

You already know Increment. It’s like getting a kill: your score goes up (+1).

Decrement is the opposite. It’s like taking damage. Your health goes down (-1).

In Verse, there are a few ways to decrement:

  1. Score Manager Decrement: Lowers the "next score" a player gets. (Useful for tricky scoring systems).
  2. Tracker Device Decrement: Lowers a specific number tracked on a device. (Perfect for counting down ammo, health, or lives).
  3. Player Counter Decrement: Lowers the count of players in a specific group. (Great for "last man standing" logic).

For this tutorial, we’ll use the Tracker Device because it’s the most intuitive. Think of it like a digital counter on a microwave. You set it to 10, and every time you press "Start," it goes to 9, 8, 7... until it hits zero.

The Scene Graph: Who’s Talking to Who?

In Unreal Engine (and Verse), everything lives in a Scene Graph. This is just a fancy way of saying "the family tree of your island."

  • The Island is the parent.
  • The Devices (like the Tracker or the Prop Mover) are children.
  • The Code is the brain that connects them.

When you write Verse, you’re essentially wiring up these devices. You tell the Tracker to count down, and when it hits zero, you tell it to send a signal to a Prop Mover to lock the door. No magic, just wiring.

Let's Build It

We’re building a One-Use Health Potion Dispenser.

  1. A Tracker Device counts down from 1 (representing 1 potion left).
  2. A Prop Mover holds the potion.
  3. When a player touches the potion, the Tracker decrements to 0.
  4. The Potion disappears (or moves away), and the dispenser locks.

The Verse Code

Copy this into your Verse file. Don’t worry, I’ll explain every line.

using { /Fortnite.com/Devices }

# This is our main "Brain" script. 
# Think of it as the game rulebook for this specific dispenser.
dispenser_brain := script():
    # We need references to the devices in our level.
    # 'tracker' is the Tracker Device we placed in the editor.
    # 'potion' is the Prop Mover holding the potion.
    tracker: TrackerDevice = TrackerDevice{ }
    potion: PropMover = PropMover{ }

    # This is the "Event" that fires when a player touches the potion.
    # In Fortnite, this is like a Trigger Volume.
    on_player_touches_potion := func(trigger: TriggerVolume):
        # STEP 1: Check if we still have potions left.
        # The Tracker's "Current Value" tells us how many are left.
        if tracker.Get_Current_Value() > 0:
            
            # STEP 2: DECREMENT!
            # This is the magic line. We lower the tracker by 1.
            # If it was 1, it becomes 0. If it was 5, it becomes 4.
            tracker.Decrement()

            # STEP 3: Give the player the potion (Heal them).
            # For this demo, we'll just move the potion away to show it's "used."
            potion.Set_Position(vector{0, 0, 0}) # Moves it to the ground (or wherever)

            print("Potion taken! Dispenser is now empty.")
        else:
            print("Dispenser is empty! Go find another one.")

    # This runs once when the game starts.
    # We "listen" for the trigger volume event.
    listen(on_player_touches_potion)

Walkthrough: What Just Happened?

  1. using { /Fortnite.com/Devices }: This tells Verse, "Hey, I want to use the Fortnite devices like Trackers and Prop Movers." Without this, Verse doesn’t know what a Tracker is.
  2. tracker: TrackerDevice = TrackerDevice{ }: This creates a variable named tracker. It’s like naming a specific Loot Bag in your inventory so you can find it later.
  3. tracker.Decrement(): This is the star of the show. It’s a function (a set of instructions that does one job). When you call this, Verse looks at the Tracker’s current number and subtracts 1.
    • Analogy: It’s like the Storm timer ticking down. You don’t have to manually change the number; the device does it for you.
  4. if tracker.Get_Current_Value() > 0: This is a condition. It’s like checking if you have ammo before shooting. If the tracker is at 0, the if block is skipped, and the player gets nothing.

Try It Yourself

Now that you’ve seen the basics, try to modify the dispenser.

Challenge: Make the dispenser refill itself after 10 seconds!

Hint:

  1. You’ll need a Timer Device.
  2. When the potion is taken (decrement happens), start the timer.
  3. When the timer finishes, use tracker.Increment() to add 1 back to the tracker.
  4. Move the potion back to its original position.

Don’t worry if it doesn’t work the first time. Even pros delete their code and start over sometimes. (Okay, maybe not that often, but we’ve all been there.)

Recap

  • Decrement is how you lower a number in Verse. It’s the opposite of increment.
  • Use Tracker Devices to count things down (ammo, health, lives).
  • Variables hold the current state of your devices.
  • Functions like Decrement() are pre-made tools that do the math for you.
  • Always check if a value is > 0 before decrementing, or you might go into negative numbers (which is fine for health, but weird for ammo).

Now go forth and subtract! Your players’ health bars (and your sanity) will thank you.

References

  • https://dev.epicgames.com/documentation/fortnite/verse-api/fortnitedotcom/devices/score_manager_device/decrement-1
  • https://dev.epicgames.com/documentation/fortnite/verse-api/fortnitedotcom/devices/score_manager_device/decrement
  • https://dev.epicgames.com/documentation/fortnite/verse-api/fortnitedotcom/devices/tracker_device/decrement
  • https://dev.epicgames.com/documentation/fortnite/verse-api/fortnitedotcom/devices/player_counter_device/decrementtargetcount
  • https://dev.epicgames.com/documentation/fortnite/verse-api/fortnitedotcom/devices/score_manager_device/increment-1

Verse source files

Turn this into a guided course

Add decrement 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.

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.

Comments

    Sign in to vote, comment, or suggest an edit. Sign in