# Piano Rabbit's Rainbow Melody
Tutorial beginner

# Piano Rabbit's Rainbow Melody

Updated beginner

# Piano Rabbit's Rainbow Melody

Welcome to Beacon 3! Today we meet Piano Rabbit. He wants your help. We will build a music machine. You will compose a song. It will be colorful and fun. Let's make some noise!

What You'll Learn

  • How to use the Note Sequencer device.
  • How to change the speed of music.
  • How to write simple Verse code to react to music.
  • How to use Variables to track notes.

How It Works

Think of a Note Sequencer like a piano roll. It is a grid. The rows are different notes. The columns are time. You click boxes to turn notes on or off.

But Verse can do more. Verse can listen. Verse can watch the music play. When a note plays, Verse can change something. Maybe it changes a light's color. Maybe it moves a prop. This is called an Event. An Event is like a trigger. It happens when something else happens.

We will also use a Variable. A variable is like a bucket. It holds one thing. Here, it will hold the note name. It changes every beat.

Let's Build It

First, place a Note Sequencer in your world. Place a Prop Mover nearby. This mover will jump when you play music.

Now, we write Verse code. This code listens to the sequencer. It makes the mover jump on every beat.

Copy this code into a Verse file in your project.

# We need to import our tools
using { /Fortnite.com/Devices }
using { /Fortnite.com/Devices/Patchwork }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

# This is our main script. It is a creative_device.
# A creative_device is the base class for all Verse scripts
# that live in a UEFN level.
PianoRabbitScript := class(creative_device):

    # This is a Variable.
    # It will hold the Note Sequencer device.
    # Think of it as a remote control for the music.
    # note: note_sequencer_device is the real UEFN device type.
    @editable
    NoteSeq : note_sequencer_device = note_sequencer_device{}

    # This is another Variable.
    # It will hold the Prop Mover.
    # Think of it as the dancer.
    # note: prop_mover_device is the real UEFN device type.
    @editable
    Dancer : prop_mover_device = prop_mover_device{}

    # This is a Function.
    # A function is a recipe. It does one job.
    # This function starts our music.
    OnBegin<override>()<suspends> : void =
        # Now we listen for events.
        # Every time the sequencer finishes one full loop,
        # we do something. This is the Event connection.
        # note: NotePlayedEvent does not exist on note_sequencer_device;
        # SequenceCompleteEvent fires at the end of each loop and is
        # the closest real signal this device exposes.
        NoteSeq.SequenceCompleteEvent.Subscribe(OnNotePlayed)

    # This function runs when the sequence completes a loop.
    # It is called by the Event above.
    OnNotePlayed() : void =
        # We print a message to the output log.
        # This helps us debug. Debugging is fixing bugs.
        Print("Sequence loop completed — beat fired!")

        # Now we make the dancer jump.
        # We tell the prop mover to begin its movement,
        # which plays the move it was configured with
        # in its device settings.
        # note: prop_mover_device has no Activate(); Begin() triggers
        # the authored movement path defined in the editor.
        Dancer.Begin()```

Let's look at the important parts.

The `OnBegin` function is special. It runs when the game starts. It connects our devices. It says, "Watch the Note Sequencer."

The `SequenceCompleteEvent` is the magic. It is a signal. It shouts, "Hey! A loop just finished!" Our code hears this shout.

The `OnNotePlayed` function is the response. It runs every time the shout happens. It makes the mover jump. You can change the speed in the Note Sequencer device settings. Try changing the **Step Rate**. Faster steps mean faster jumps!

## Try It Yourself

Can you make the music change the color of a light?

1.  Add a **Light** device to your scene.
2.  Add it to your Verse script as a new variable.
3.  In `OnNotePlayed`, change the light's color.
4.  Use different colors for different notes.

**Hint:** Look for the `SetColor` function on the Light device. You can use `vector3{X:=1.0, Y:=0.0, Z:=0.0}` for red. Try `vector3{X:=0.0, Y:=1.0, Z:=0.0}` for green!

## Recap

You built a musical machine! You learned about **Note Sequencers**. You used **Variables** to store devices. You used **Events** to react to music. You made code that listens and responds. Great job, coder!

## References

*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/build-lego-music-concert-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite/build-your-own-lego-music-concert-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite/yacht-heist-4-the-escape-phase-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/build-patchwork-x-yacht-heist-4-escape-phase-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite/yacht-heist-3-the-sneak-phase-in-fortnite-creative

Verse source files

Turn this into a guided course

Add Beacon 3: Piano Rabbit 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