Verse Library verse

01 Device

Listens for button interactions and uses a value setter device to mute associated music playback.

verse-library/off-value-setter/01-device.verse

# This is the main script for our music switch.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Devices/Patchwork }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

MyMusicSwitch := class(creative_device):
    # This is the button device.
    @editable
    ButtonDevice : button_device = button_device{}

    # This is the music device.
    @editable
    MusicDevice : speaker_device = speaker_device{}

    # This is the Value Setter device.
    # It connects the button to the music.
    @editable
    VolumeSetter : value_setter_device = value_setter_device{}

    # This function runs when the game starts.
    OnBegin<override>()<suspends> : void =
        # We connect the button's "Pressed" event to our script.
        ButtonDevice.InteractedWithEvent.Subscribe(OnButtonPressed)

    # This function runs when the button is pressed.
    OnButtonPressed(Agent : agent) : void =
        # We use the Value Setter to change the volume.
        # We set it to 0.0 to turn the music off.
        VolumeSetter.SetValue(0.0)

Comments

    Sign in to vote, comment, or suggest an edit. Sign in