The Light Switch Algorithm: Planning Your First Verse Device
Tutorial beginner

The Light Switch Algorithm: Planning Your First Verse Device

Updated beginner

The Light Switch Algorithm: Planning Your First Verse Device

Have you ever wanted to build a secret room in Fortnite? Or a puzzle that only opens when you flip the right switches? To make these cool things, you need to tell the game exactly what to do. But before you write any code, you need a plan. Think of it like baking a cake. You don't just throw ingredients in a bowl. You follow a recipe! In programming, this recipe is called an algorithm. Today, we will plan a "Tagged Lights" puzzle. You will learn how to find specific objects in your world and check if they are on or off.

What You'll Learn

  • What an algorithm is (it's just a fancy word for a plan).
  • How to use tags to find specific lights in your island.
  • How to check if a light is turned on or off.
  • How to write a simple pseudocode plan before coding.

How It Works

Imagine you are a detective. Your job is to find three specific light switches in a dark room. You know they are there, but you don't know where. You also need to know if they are flipped up or down.

In Fortnite, we use Tags to label things. A tag is like a sticky note you put on an object. If you put a sticky note that says "RedLight" on a lamp, your code can find that lamp easily. You don't need to know its exact position. You just ask, "Where is the thing with the 'RedLight' tag?"

An algorithm is the step-by-step plan to solve a problem. For our puzzle, the plan looks like this:

  1. Find all the lights that have the "PuzzleLight" tag.
  2. Check each light one by one.
  3. Ask: "Is this light turned on?"
  4. If it is on, remember that fact.
  5. If all the right lights are on, open the secret door!

We write this plan down in plain English first. This is called pseudocode. It helps us think clearly before we worry about the tricky Verse syntax.

Let's Build It

Let's write the pseudocode for our Tagged Lights puzzle. This isn't real Verse code yet. It's just our brain talking to our future self.

# ---------------------------------------------------------------
# PSEUDOCODE — plain-English plan, not runnable Verse yet.
# Each step below maps to a real concept we will code later.
# ---------------------------------------------------------------

# Step 1: Find the lights
# We ask the game to find all creative_prop objects whose
# gameplay tag matches "PuzzleLight".
all_lights = GetCreativeObjectsWithTag(tag{"PuzzleLight"})

# Step 2: Start checking them
# We will look at each light in our list.
for (Light : all_lights):

    # Step 3: Check the state
    # Is the light currently turned on?
    # creative_prop exposes IsEnabled() for this purpose.
    if (Light.IsEnabled[] = true):

        # Step 4: Remember the result
        # We add this light to our "On" list.
        on_lights_list += array{Light}

# Step 5: Check the win condition
# Did we find all the lights we needed?
if (on_lights_list.Length = total_needed):

    # Step 6: Win!
    # Signal the door device to open.
    SecretDoor.Open()

Walkthrough

  • GetCreativeObjectsWithTag: This is like using a metal detector. It scans the whole level and finds everything with that specific tag.
  • for: This is a loop. It means "do this action for every single item in the list." Imagine eating cookies one by one from a plate.
  • IsEnabled[]: This asks a question. The answer is either True (yes, it is on) or False (no, it is off).
  • SecretDoor.Open(): This is the fun part! When the condition is met, we trigger the next event.

Try It Yourself

Now that you have a plan, it's time to make it real!

Challenge: Open UEFN and create a simple island. Place three point lights. Tag them all with the same tag name (like "TestLight"). Then, try to write the Verse code for the GetCreativeObjectsWithTag part.

Hint: In Verse, you use the GetCreativeObjectsWithTag function and pass it a tag value written like tag{"TestLight"}. Remember to give your device a name so it can run!

Recap

You just learned how to plan a game mechanic before writing code. You learned that an algorithm is just a step-by-step plan. You used tags to find objects easily. And you wrote pseudocode to organize your thoughts. Great job! You are thinking like a real programmer.

References

  • https://dev.epicgames.com/documentation/en-us/fortnite/tagged-lights-1-creating-the-algorithm-in-verse
  • https://dev.epicgames.com/documentation/en-us/uefn/tagged-lights-1-creating-the-algorithm-in-verse
  • https://dev.epicgames.com/documentation/en-us/uefn/gameplay-tags-in-verse
  • https://dev.epicgames.com/documentation/fortnite/verse-tags-in-fortnite
  • https://dev.epicgames.com/documentation/en-us/fortnite/create-your-own-device-in-verse

Verse source files

Turn this into a guided course

Add tagged-lights-1-creating-the-algorithm-in-verse 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