# This is a Verse Script for Rocket Racing Respawning # Think of this as the "Rulebook" for your island. using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # We declare our script as a class that extends creative_device. # Every Verse script that interacts with UEFN devices must do this. racing_logic := class(creative_device): # 1. Define the Devices (The Actors) # We need to tell Verse which devices we are controlling. # In programming, this is called "Binding" or "Referencing." # Imagine pointing at a device and saying "You, you're in charge." # # These are @editable properties, which means they show up as # slots in the UEFN editor. You drag your placed devices into # those slots to connect them. No "Find by name" required. @editable StartSpawner : vehicle_spawner_device = vehicle_spawner_device{} @editable RespawnTrigger : trigger_device = trigger_device{} @editable CrashZone : trigger_device = trigger_device{} # 2. Define Variables (The State) # A variable is a container for data. # Here, we'll store whether a respawn is already in progress, # so we don't accidentally trigger two spawns at once. # The 'var' keyword means this value can change during the game. var bRespawning : logic = false # 3. The Main Event Loop (The Heartbeat) # This function runs when the game starts. # It sets up the listeners for our triggers. OnBegin() : void = # When the RespawnTrigger is activated, run this code: RespawnTrigger.TriggeredEvent.Await() # "Hey, someone stepped in the respawn zone! Send them back!" spawn { RespawnCar() } # When the CrashZone is activated, run this code: CrashZone.TriggeredEvent.Await() # "Oh no, a crash! Let's reset the car." spawn { RespawnCar() } # 4. The Spawner Function (The Action) # This is a custom function we created. # It resets the vehicle by telling the spawner to respawn. RespawnCar() : void = # Guard against multiple simultaneous respawns. if (not bRespawning?): set bRespawning = true # First, reset (despawn) any existing vehicle managed # by this spawner, then immediately spawn a fresh one. # Reset() despawns the current vehicle so the spawner # is ready to produce a clean car. StartSpawner.Reset() # We wait a tiny fraction of a second so the game can # process the despawn before spawning the new vehicle. # This is called "Suspension" or "Waiting." # Think of it as taking a deep breath before shouting. Sleep(0.1) # Enable the spawner so it produces a fresh vehicle # at its placed start-line position. StartSpawner.Enable() # For now, let's just print a message to the debug log # (the Output Log in UEFN). This helps you know the # code is working during playtests. Print("Car has been respawned at the start line!") # Allow future respawns once this one is complete. set bRespawning = false