# This is a "Device" in Verse. Think of it as a custom gadget you place in the world. # It’s like a Race Manager, but instead of timing laps, it tracks loot points. LootGoblinScore: device = # --- VARIABLES (The "Boxes" for our data) --- # TotalScore is like your current XP bar. It changes constantly. # We start it at 0. var TotalScore: int = 0 # PendingScore is like a "cart" before you check out. # We add points here first, then dump them into TotalScore later. # This prevents glitches if multiple things happen at once. var PendingScore: int = 0 # This is a reference to the Score Manager device in the editor. # We need to link this in the editor later! ScoreManagerDevice: score_manager_device = score_manager_device{} # This is the text box on the screen. # We’ll use this to show the player their score. ScoreText: text_block = text_block{} # --- FUNCTIONS (The "Buttons" for logic) --- # This function adds points to the "cart" (PendingScore). # Imagine picking up a crate. You don't update the screen immediately. # You just add it to your pocket. AddPoints(Points: int) : void = PendingScore += Points # We call UpdateUI to refresh the screen. # "defer" means "do this after everything else in this frame is done." # It’s like waiting for the storm to finish shrinking before you check your HP. defer: UpdateUI() # This function moves points from the "cart" to the "bank" (TotalScore). # It also updates the visual text on the screen. UpdateUI() : void = # Move pending points to total score. TotalScore += PendingScore # Reset the cart to 0 for the next pickup. PendingScore = 0 # Now, tell the Score Manager device to update its value. # SetScoreAward sets the number the device knows about. ScoreManagerDevice.SetScoreAward(TotalScore) # Update the text block on the screen. # We convert the integer (number) to a string (text) to display it. ScoreText.SetContent($"{TotalScore}") # Finally, activate the Score Manager to show the UI to the player. # This is like pressing "Show Scoreboard" on the gamepad. ScoreManagerDevice.Activate() # --- EVENT HANDLERS (What happens when stuff triggers) --- # This event runs when the device starts. # It’s like when the bus drops you off and the game begins. OnBegin(): void = # Initialize the text block to show "0" at the start. ScoreText.SetContent("0") # Activate the UI so the player sees it immediately. ScoreManagerDevice.Activate()