# This is the main script for our Obby Manager # Think of this as the "Game Rules" document using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # A Verse device must be declared as a class that extends creative_device. # Think of creative_device as the "base" that every Verse script in UEFN inherits from. obby_manager := class(creative_device): # 1. DEFINE VARIABLES (The Loot Pool) # We need a counter to track coins. # 'int' means Integer (a whole number, no decimals). # 'CoinCount' is the name of our variable. # It starts at 0. # 'var' makes it mutable so we can change it later. var CoinCount : int = 0 # We need to know how many coins are in the level total. # This is a CONSTANT. It never changes. # Think of it like the number of rings in Mario Kart: it's always 3. TotalCoins : int = 5 # 2. DEFINE THE PLAYER START (The Respawn Point) # We need to tell the code where to send players if they fall. # We'll link this to a specific Player Start device in the editor later. # '@editable' exposes the field so you can drag a device into it in UEFN. @editable PlayerStartDevice : player_spawner_device = player_spawner_device{} # 3. DEFINE THE COINS (The Trigger Devices) # We need a list of all the coin trigger devices. # Each "coin" is represented by a trigger_device placed in the level. # '@editable' lets you assign all five in the UEFN details panel. @editable CoinTriggers : []trigger_device = array{} # 4. OnBegin: Called automatically when the game session starts. # This is where we wire up our events — like setting all the traps # before players load in. OnBegin() : void = # Loop over every coin trigger and subscribe to its # TriggeredEvent so we know when a player walks into it. for (Coin : CoinTriggers): Coin.TriggeredEvent.Subscribe(OnCoinCollected) # 5. THE EVENT: When a Player Touches a Coin # 'TriggeredEvent' fires when a player walks into a trigger_device. # The payload is the agent (player) who activated it. OnCoinCollected(Agent : ?agent) : void = # Add 1 to our CoinCount variable # This is like gaining XP. The number goes up. set CoinCount += 1 # Print a message to the screen (Debugging) # Think of this as the "Elimination Feed" but for coins Print("Coin Collected! Total: {CoinCount}") # CHECK IF WIN CONDITION IS MET # If CoinCount is equal to TotalCoins... if (CoinCount = TotalCoins): Print("YOU WIN! Obby Complete!") # In a full game, we'd unlock the next area here. # For now, let's just celebrate. # 6. THE EVENT: When a Player Falls Off the Map # Call this from a separate kill-zone trigger_device wired up # in OnBegin (see Step 3 notes). The player is sent back to start # and the coin counter resets for a true challenge. OnPlayerFell(Agent : agent) : void = # Send the player back to the start. # player_spawner_device.Spawn() teleports the agent to the spawn pad. # note: player_spawner_device.Spawn() is the real API for respawning # an agent at a spawner; there is no bare Player.Respawn() call. PlayerStartDevice.Spawn(Agent) # Reset the coin count for a true challenge. ResetCoins() # HELPER FUNCTION: Reset the Game State # A 'Function' is a reusable block of code. # Think of it like a 'Reset Match' button. ResetCoins() : void = set CoinCount = 0 Print("Respawned! Coins reset.")