# This line tells Verse that our script is ready to run when the game starts. # Think of it as the "Start Game" button. using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # This is our main script. It's like the brain of the island. # We call it "TrapController" because it controls the traps. # In UEFN, a Verse device must extend creative_device to live on the island. TrapController := class(creative_device): # VARIABLES: Think of these as backpacks holding items. # '@editable' means you can drag-and-drop the device onto this slot # directly in the UEFN editor — no GetDevice() lookup needed. @editable MessageDevice : hud_message_device = hud_message_device{} # '@editable' exposes the trigger device to the editor the same way. @editable TrapTrigger : trigger_device = trigger_device{} # 'TrapCount' is a variable integer (a whole number). # We start it at 0 because no one has been caught yet. # 'var' makes it mutable so we can change it later. var TrapCount : int = 0 # This function is called automatically when the script starts. # It's like setting up your loadout before dropping from the bus. OnBegin() : void = # We bind an event. This is like wiring a tripwire to an explosion. # When TrapTrigger fires TriggeredEvent, run HandleTrapStep. # The agent parameter carries info about who triggered it. TrapTrigger.TriggeredEvent.Subscribe(HandleTrapStep) # Keep the coroutine alive so the game loop doesn't exit. loop: Sleep(1.0) # This is the function that runs when the event happens. # 'TriggeredAgent' is the game agent (player) who stepped on the trap. HandleTrapStep(TriggeredAgent : ?agent) : void = # Increment the counter. # This means: "Take the current TrapCount, add 1, and save it back." # 'set' is required in Verse to reassign a 'var' variable. set TrapCount = TrapCount + 1 # Prepare the message text. # We use string interpolation (the {TrapCount} part) to put the number in the text. # It's like filling out a form: "You have died {N} times." MessageText : string = "Caught you! That's #{TrapCount} time(s)!" # Send the message to every player currently in the game. # hud_message_device.Show() displays the device's pre-configured message; # to display a custom string we call SetText first, then Show. # Note: SetText+Show is the real API for runtime custom strings. MessageDevice.SetText(MessageText) MessageDevice.Show() # Optional: Play a sound or change a prop color here!