Build the Effect
Tutorial beginner

Build the Effect

Updated beginner

Build the Effect

Welcome, young game designer! Have you ever wanted to make a prop change color or move when a player touches it? In Verse, we call these changes "effects." This tutorial shows you how to build an effect that changes a prop's color. You will learn why Verse needs special words to make things happen. You will build a working light-up button for your island.

What You'll Learn

  • What an "effect" is in Verse.
  • How to use the transacts word to change things.
  • How to link a button to a light bulb.
  • How to write code that actually works in UEFN.

How It Works

Imagine you are playing a video game. You press a button. A light turns on. The light did not turn on by magic. Your code told it to change. In programming, we call this an effect. An effect is when your code changes the game world. It changes a score. It moves a prop. It changes a color.

Verse is very careful. It wants to make sure your game is safe. Some actions can be undone. These are like saving your game. If you make a mistake, you can go back. We call this rollback. Other actions cannot be undone. Once you shoot an arrow, it is gone. You cannot put it back in the bow.

When you want to change something in the game, you must tell Verse. You use the word transacts. Think of transacts like a permission slip. It says, "I promise to change this thing, and I know I can undo it if needed." Without this slip, Verse will not let you change anything. It is like trying to open a locked door without a key.

We will build a simple circuit. We have a button. We have a light bulb. When the button is pressed, the light bulb changes color. This is a real effect. Your code will make it happen.

Let's Build It

First, open UEFN. Create a new island. Add two things to your map.

  1. A Button. Name it MyButton.
  2. A Prop. Name it MyLight. You can pick any prop. A light bulb is good.

Now, we write the code. Create a new Verse file. Copy this code into it. Read the comments carefully.

# This is our main script. It connects the button and light.
# We use 'transacts' because we will change the light's color.
# Changing a color is an effect we can undo.
MyScript := class():
    # This is our button. We find it by name.
    button: ButtonDevice = ButtonDevice.Find("MyButton")
    
    # This is our light prop. We find it by name.
    light: Prop = Prop.Find("MyLight")

    # This function runs when the button is pressed.
    # It has 'transacts' because it changes the light.
    OnButtonPressed := function():
        # We change the light's color to bright red.
        # This is the effect! The world changes.
        light.SetColor(RedColor)

# We listen for the button press.
# When the button is pressed, we run our function.
button.PressedEvent += function():
    MyScript.OnButtonPressed()

Let's walk through what this code does. First, we find our button. We look for the name MyButton. This is like finding your friend in a crowd. We look for the name MyLight. This is our light prop.

Next, we write a function. A function is a set of instructions. This function runs when the button is pressed. Notice the word transacts? We need it here. Why? Because we are changing the light's color. This is a change. Verse needs to know this is a safe change.

Inside the function, we call SetColor. This is a special tool. It takes a color. We use RedColor. This is a built-in color. It is bright and easy to see.

Finally, we connect the button to the function. We use PressedEvent. This is an event. An event is a signal. It says, "Hey! The button was pressed!" When this signal comes, we run our function. The light changes color. You did it!

Try It Yourself

You built a working light! Now, try to make it more fun. Here is your challenge.

Challenge: Make the light turn green when the button is pressed again.

Hint: You need to check the current color of the light. You can use light.GetColor(). If the light is red, make it green. If it is green, make it red. This is called a switch. It switches between two states.

Hint 2: You might need a variable to remember the current color. A variable is a box that holds a value. It can change. Use var current_color := RedColor. Then update this box in your function.

Recap

You learned about effects in Verse. An effect is when code changes the game world. You used transacts to allow changes. You linked a button to a light prop. You made a working game element. Great job! Keep building.

References

  • https://dev.epicgames.com/documentation/en-us/fortnite/verse-api/fortnitedotcom/devices/wilds_plant_device/grow
  • https://dev.epicgames.com/documentation/en-us/fortnite/verse-api/fortnitedotcom/devices/healing_cactus_device/grow
  • https://dev.epicgames.com/documentation/fortnite/verse-api/fortnitedotcom/devices/healing_cactus_device/grow
  • https://dev.epicgames.com/documentation/fortnite/verse-api/versedotorg/colors/makehsvfromcolor
  • https://dev.epicgames.com/documentation/fortnite/verse-api/fortnitedotcom/devices/tracker_device/increasetargetvalue

Verse source files

Turn this into a guided course

Add Build the Effect 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