using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } using { /Verse.org/Localization } # 2. THE SCRIPT CLASS: This is your "Island" wave_controller := class(creative_device): # 3. REFERENCES: Connecting our code to the devices in the world # Think of these as "cables" from the code to the device # Select the matching device in the UEFN Details panel for each property @editable WaveInfoBillboard : billboard_device = billboard_device{} @editable StartButton : button_device = button_device{} @editable WaveTimer : timer_device = timer_device{} @editable EnemySpawner : creature_spawner_device = creature_spawner_device{} # 4. VARIABLES: Tracking our game state var CurrentWave : int = 0 MaxWaves : int = 3 # 6. BINDING EVENTS: Connecting the triggers to the functions # OnBegin runs automatically when the game session starts OnBegin() : void = # When the button is pressed, start the wave StartButton.InteractedWithEvent.Subscribe(OnStartButtonPressed) # When the timer finishes, end the wave WaveTimer.SuccessEvent.Subscribe(OnWaveTimerFinished) # Show the initial prompt on the billboard WaveInfoBillboard.SetText(LocalizeMessage("Press Button for Wave 1")) # Wrapper so the button event signature (agent) feeds into StartWave OnStartButtonPressed(Agent : agent) : void = StartWave() # Wrapper so the timer event signature (agent) feeds into EndWave OnWaveTimerFinished(Agent : ?agent) : void = EndWave() # 5. FUNCTIONS: The logic for what happens # Function to Start a Wave StartWave() : void = # Update the variable set CurrentWave = CurrentWave + 1 # Check if we've passed the max waves if (CurrentWave > MaxWaves): WaveInfoBillboard.SetText(LocalizeMessage("All Waves Complete! Victory!")) return # Stop here, don't start another wave # Update the Billboard text WaveInfoBillboard.SetText(LocalizeMessage("Wave {CurrentWave} Starting!")) # Enable the spawner so enemies can appear EnemySpawner.Enable() # Start the timer for this wave WaveTimer.Start() # Function to End a Wave (Called when timer finishes) EndWave() : void = # Disable the spawner so no more enemies spawn EnemySpawner.Disable() # Reset the timer for the next round WaveTimer.Reset() # Update the billboard to prompt the player if (CurrentWave < MaxWaves): WaveInfoBillboard.SetText(LocalizeMessage("Press Button for Wave {CurrentWave + 1}")) else: WaveInfoBillboard.SetText(LocalizeMessage("Final Wave Cleared! You Win!"))