Make Music Play When You Step: The Note Trigger
Tutorial beginner

Make Music Play When You Step: The Note Trigger

Updated beginner

Make Music Play When You Step: The Note Trigger

Do you like music? Do you like building cool islands? What if you could make a song play only when a player walks on a specific tile? That is exactly what we are going to build! We will use a special device called a Note Trigger. It is like a musical tripwire. When someone steps on it, ding! The music starts.

What You'll Learn

  • What a Device is in Verse.
  • How to connect a Note Trigger to your code.
  • How to turn devices On and Off.
  • How to make a simple musical event happen.

How It Works

Imagine your island is a stage. The Note Trigger is a special floor tile. It listens for footsteps. When a player steps on it, it sends a signal. This signal is like a text message. The message says, "Hey! Someone is here!"

In Verse, we write a script to read that message. We call this script a Device Class. Think of it as the brain of your trap or tile. The brain has two main jobs:

  1. Start Up: When the game begins, the brain wakes up. It checks if the music device is ready.
  2. React: When the trigger fires, the brain tells another device to play a sound or change color.

We will use the Note Trigger device. This device is part of the Patchwork tools. Patchwork tools are like special LEGO bricks for music and effects. We will link our Verse code to this brick. Then, we will tell the code to turn on a Prop Mover or a Light when the note triggers. For this tutorial, we will make a light flash! It is simple and looks great.

Let's Build It

Here is the code for our musical light trap. Copy this into a new Verse file in your project.

using { /Fortnite.com/Devices }
using { /Fortnite.com/Devices/Patchwork }
using { /Verse.org/Simulation }

# This is our brain. It controls the trap.
# We name it 'MusicalLightTrap'.
MusicalLightTrap := class(creative_device):

    # This is the Note Trigger device.
    # It waits for a player to step on it.
    @editable
    NoteTrigger : note_trigger_device = note_trigger_device{}

    # This is the light we want to turn on.
    @editable
    MyLight : customizable_light_device = customizable_light_device{}

    # This runs when the game starts.
    OnBegin<override>()<suspends> : void =
        # Print a message to check if it works.
        Print("The trap is ready!")

        # Wait for the trigger signal.
        # This line waits forever until the note triggers.
        # note: TriggeredEvent fires when the note_trigger_device activates.
        NoteTrigger.TriggeredEvent.Await()

        # Once triggered, turn on the light!
        MyLight.TurnOn()

        # Print a message to say it worked.
        Print("Light is ON!")```

### Walkthrough

Let's look at the code line by line.

*   `using { /Fortnite.com/Devices }`: This tells Verse, "I want to use Fortnite devices." It is like opening your toolbox.
*   `MusicalLightTrap := class(creative_device):`: This creates a new type of device. You can place this in your level.
*   `@editable`: This tag means you can see this variable in the editor. You can drag and drop devices onto these slots.
*   `NoteTrigger:note_trigger_device`: This is a slot for the Note Trigger. You must place a Note Trigger device in your level and drag it into this slot in the editor.
*   `OnBegin`: This function runs once when the island starts. It is the perfect place to set up your trap.
*   `NoteTrigger.NoteTriggeredEvent.Await()`: This line is magic. It pauses the code. It waits right here until the Note Trigger fires. It is like standing still and waiting for a bell to ring.
*   `MyLight.TurnOn()`: Once the bell rings, this line runs. It turns the light on.

## Try It Yourself

Now it is your turn to build!

1.  Place a **Note Trigger** device in your level.
2.  Place a **Light** device nearby.
3.  Create a new Verse file and paste the code above.
4.  In the editor, select your Verse device. Drag the Note Trigger and the Light into the slots in the details panel.
5.  Play your island! Walk on the Note Trigger. Does the light turn on?

**Challenge:** Can you make the light turn **off** after 3 seconds? Hint: Look up the `Sleep` function in Verse. It makes the code wait for a certain amount of time.

## Recap

You just built a device that reacts to music triggers! You learned how to use a **Note Trigger** to detect events. You learned how to connect devices using `@editable` slots. And you learned how to make things happen in the game world with Verse. Great job!

## References

*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-patchwork-note-trigger-devices-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite/using-patchwork-note-trigger-devices-in-fortnite-creative
*   https://dev.epicgames.com/documentation/fortnite/verse-api/fortnitedotcom/devices/patchwork/note_trigger_device
*   https://dev.epicgames.com/documentation/en-us/fortnite/verse-api/fortnitedotcom/devices/patchwork/note_trigger_device
*   https://dev.epicgames.com/documentation/en-us/fortnite/verse-api/fortnitedotcom/devices/trigger_device/trigger-1

Verse source files

Turn this into a guided course

Add Note Trigger API to your free study plan — we'll suggest related pages and stitch the lot into one compile-checked, self-guided lesson with worked examples and quizzes.

Original tutorial generated by Verse Island from the Verse/UEFN knowledge base, with references to the Epic Games sources above. Code is validated against the knowledge base.

Comments

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