Verse Library verse

01 Device

Manages player currency and purchase logic, validating balances and deducting costs when buying items.

verse-library/data-manipulation-and-arithmetic/01-device.verse

# Import the basic tools we need
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Native }

# Define our Shop Logic
ShopLogic := class(creative_device):
    # 1. Define our Variables (The "Inventory Slots")
    # These are 'int' because coins are whole numbers
    var PlayerCoins : int = 100          # Starting gold in the shop
    var ItemCost : int = 25              # Cost of the weapon
    var ItemName : string = "Assault Rifle" # What we are selling

    # 2. The Function (The "Trigger" Action)
    # This runs when we call BuyItem()
    BuyItem() : void =
        # Check if we have enough coins (Equality Operator: =)
        if (PlayerCoins >= ItemCost):
            # 3. Compound Assignment (The Shortcut)
            # Subtract cost from coins: PlayerCoins = PlayerCoins - ItemCost
            set PlayerCoins -= ItemCost 
            
            # Add the item to the player (Simplified logic for demo)
            # In real UEFN, you'd use ItemGranter here
            Print("Purchased " + ItemName + "! Remaining Coins: " + string("{PlayerCoins}"))
        else:
            # Not enough gold!
            Print("Not enough gold! You need " + string("{ItemCost - PlayerCoins}") + " more.")

    # 4. The Start Event (When the game begins)

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.

Sign in with Discord

Comments

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