audio_player_device

device
audio_player_device<public> := class<concrete><final>(creative_device_base)

Used to configure and play audio from the device location or from registered `agent`s.

Module
/Fortnite.com/Devices
Source
fortnite

Used in

scream_trap_device := class(creative_device):

    # This is our 'Backpack' (Component) that will hold the audio.
    # audio_player_device is a real UEFN device you place on your island
    # and wire up in the editor. It wraps your imported sound asset.
    # Drag an Audio Player Device from the device list onto your island,
    # then assign it to this slot in the Verse Device details panel.
    @editable
    AudioPlayer : audio_player_device = audio_player_device{}

    # This is our trigger — the pressure plate the player walks over.
    # Place a Trigger Device on your island and assign it here.
    @editable
    Trap : trigger_device = trigger_device{}

    # This function runs ONCE when the island starts.
    # Think of this as the 'Pre-Match Lobby' phase.
    OnBegin<override>()<suspends> : void =
        # Subscribe to the trigger's TriggeredEvent.
        # Whenever a player steps on the Trap, TriggerSound is called.
        # This is like the Bus picking up the playlist before the drop.
        Trap.TriggeredEvent.Subscribe(OnTrapped)

    # This function runs when a player steps on the trigger.
    # The agent parameter is the player who activated the trap.
    OnTrapped(Agent : ?agent) : void =
        # Tell the AudioPlayer device to play its assigned sound asset.
        # The sound asset itself is configured on the audio_player_device
        # in the UEFN editor — set it to your imported ScreamSample there.
        # This is the 'Drop'. Instant playback.
        AudioPlayer.Play()
ambient_sound_device := class(creative_device):

    # Drag your placed Audio Player Device onto this slot in the Details panel.
    @editable
    AmbientHum : audio_player_device = audio_player_device{}

    OnBegin<override>()<suspends> : void =
        # Make sure the device is live, then start its (looping) sound.
        AmbientHum.Enable()
        AmbientHum.Play()
        Print("Ambient bed playing")
JewelHeistDevice := class(creative_device):

    # This is the music track for sneaking.
    @editable
    SneakTrack : audio_player_device = audio_player_device{}

    # This is the music track for escaping.
    @editable
    EscapeTrack : audio_player_device = audio_player_device{}

    # This function runs when the game starts.
    OnBegin<override>()<suspends>:void=
        # Start the sneaking music.
        SneakTrack.Play()

    # This function runs when a player touches the jewel.
    OnPlayerTouchedJewel(Player: agent):void=
        # Stop the sneaking music.
        SneakTrack.Stop()
        # Start the escape music!
        EscapeTrack.Play()
        
        # Print a message to the screen.
        Print("Heist started! Run!")
# Without this line, Verse won't know what a 'customizable_light_device' or
# 'audio_player_device' is.
using { /Fortnite.com/Devices }

# We also need the core module for suspends and basic language features.
using { /Verse.org/Simulation }

# 2. DEFINE THE CLASS (The 'Island' object)
canyon_echo_manager := class(creative_device):

    # Drag the placed Audio Player device here in the Details panel.
    @editable
    MusicSource : audio_player_device = audio_player_device{}

    # Drag the placed Trigger Volume device here in the Details panel.
    # The Echo Effect and Output devices are wired to MusicSource
    # inside Patchwork — no Verse API is needed for that routing.
    @editable
    EntranceTrigger : trigger_device = trigger_device{}

    OnBegin<override>()<suspends> : void =
        # Subscribe to the trigger so playback starts when a
        # player walks into the Canyon Chamber.
        EntranceTrigger.TriggeredEvent.Subscribe(OnPlayerEntered)

    # Called automatically each time the trigger fires.
    # 'Agent' is the player who stepped inside.
    OnPlayerEntered(Agent : ?agent) : void =
        # Start the music source.
        # The Patchwork chain (MusicSource → Echo Effect → Output)
        # is already configured in the editor, so the echo plays
        # automatically once the source begins.
        MusicSource.Play()
        # note: Echo Effect Delay (0.3 s), Feedback (0.7), and
        # Mix (0.5) are set on the Echo Effect device in the
        # UEFN Details panel — there is no runtime Verse API
        # for adjusting Patchwork parameters at play-time.
# The zone that detects a player stepping in.
    @editable
    EntryPad : trigger_device = trigger_device{}

    # The one-shot sound effect to fire on entry.
    @editable
    StingerSfx : audio_player_device = audio_player_device{}

    OnBegin<override>()<suspends> : void =
        StingerSfx.Enable()
        # Handle one entry per loop iteration, forever.
        loop:
            # Block here until someone steps into the pad. The event sends the
ChaosTile := class(creative_device):

    # This is our "Variable" for the sound.
    # Think of this like a slot in your inventory where you drag your audio file.
    # In UEFN, this appears in the Customize panel.
    @editable
    ChaosSound: audio_player_device = audio_player_device{}

    # This is the "Trigger Zone."
    # Imagine an invisible bubble around the tile.
    @editable
    TriggerZone: trigger_device = trigger_device{}

    # This is the "Event Handler."
    # When a player enters the TriggerZone, this function runs.
    # It's like a motion sensor on a security camera.
    OnPlayerEnter(Agent: ?agent): void =
        # Check if the thing that entered is actually a player
        if (A := Agent?, Player := player[A]):
            # Play the sound!
            # This is like hitting the "Play" button on a remote.
            ChaosSound.Play()

            # Optional: Give them a point or a notification
            # We'll just print a message to the console for now
            Print("CHAOS ACTIVATED!")

    # This function sets up the device when the game starts
    OnBegin<override>()<suspends>: void =
        # Connect the event to the function
        # This wires the "sensor" to the "alarm"
        TriggerZone.TriggeredEvent.Subscribe(OnPlayerEnter)
chaos_button_system := class(creative_device):
    # We define variables for our devices.
    # These are like your "inventory slots" for devices.
    TriggerDevice: trigger_device = trigger_device{}
    SpeakerDevice: audio_player_device = audio_player_device{}
    LightDevice: customizable_light_device = customizable_light_device{}
    MoverDevice: prop_mover_device = prop_mover_device{}

    # The 'On Begin' function runs when the island starts.
    # This is where we do all our "introductions" (binding).
    OnBegin<override>()<suspends>: void =
        # BINDING 1: The Trigger -> The Speaker
        # When the trigger is activated, call the Speaker's "Play" function.
        TriggerDevice.TriggeredEvent.Subscribe(OnTriggered)

        # Note: In real UEFN, you can also do this visually in the device UI,
        # but seeing it in code makes the "Event -> Function" link crystal clear.

    OnTriggered(Agent: ?agent): void =
        # BINDING 2: The Trigger -> The Light
        # When the trigger is activated, call the Light's "Set Active" function.
        # We pass 'true' to turn it ON.
        LightDevice.TurnOn()

        # BINDING 3: The Trigger -> The Prop Mover
        # When the trigger is activated, call the Mover's "Move" function.
        MoverDevice.Begin()
# These are the "knobs" you see in the device panel in UEFN.
    
    # 1. The Sound File
    # We link this to an Audio Player device. 
    # When you place this device in UEFN, you'll drag a sound file into this slot.
    @editable
    Sound:audio_player_device := audio_player_device{}
    
    # 2. Should it repeat?
    # If true, the guard can say the same line twice in a row.
    # If false, it waits a cooldown before repeating.
    @editable
    CanRepeat:logic = true