Build CodewoodKit: Your First Shared Module

In this lesson you'll learn to

  • ✓Author a reusable helper module (FormatTime, Distance, PickRandom) that later zones import — the start of the cross-zone module arc.

Author a reusable helper module (FormatTime, Distance, PickRandom) that later zones import — the start of the cross-zone module arc.

📖 Reference & full walkthrough: Build CodewoodKit: Your First Shared Module

🧩 Your capstone piece: CodewoodKit module — exported to east-volcano/west-coves/the-deeps


Stop Copy-Pasting Code: Master Verse Modules Like a Pro

Imagine you’re building a massive Battle Royale island with 50 different traps. You decide that every trap should play a specific "explosion" sound effect. If you hardcode that sound into every single trap device, you’re setting yourself up for a nightmare. What if you want to change the sound later? You’d have to open 50 files, find the sound, and change it. That’s like trying to edit every wall in your base individually instead of just changing the material once.

Enter Modules.

In Verse, a module is like a reusable loot box of code. You write the logic once, save it in its own file, and then "drop" it into any other script that needs it. It keeps your code clean, prevents bugs from spreading, and saves you from the headache of repetitive editing. In this tutorial, we’ll build a simple "Health Potion" system where the potion’s stats (name, heal amount, cooldown) are stored in a module, so we can share those exact stats across multiple potions without duplicating a single line of code.

What You'll Learn

  • What a Module is: Think of it as a shared inventory for code variables and logic.
  • How to Create a Module: Writing a separate .verse file to hold your data.
  • How to Import a Module: Using the using statement to bring that data into your main island script.
  • Why This Matters: Understanding how to keep your island organized so it doesn’t crash when you add more content.

How It Works

The Problem: The "Copy-Paste" Trap

In programming, Duplication is the enemy. If you have the same variable (like PotionName) defined in ten different scripts, and you want to change it from "Health Potion" to "Super Health Potion," you have to hunt down all ten instances. If you miss one, your game breaks or behaves weirdly.

The Solution: The Module

A Module is an atomic unit of code. "Atomic" means it’s a single, indivisible block. You define your data or logic inside a module file, mark it as public (which means "open to everyone"), and then other scripts can import it.

Think of it like this:

  • The Module File: This is your Loot Pool. You decide what items are in the pool (e.g., a sword, a shield, a potion). You set these rules once.
  • The Main Script: This is the Player. The player doesn’t know how the sword is balanced; they just grab it from the pool. If you change the sword’s damage in the Loot Pool, every player who picks it up gets the new damage.

Key Concepts

  1. module Keyword: This tells Verse, "This file isn’t a standalone game; it’s a library of stuff for other files to use."
  2. <public>: This is the gate. By default, code in a module is private (hidden). Adding <public> is like putting a "Take Me!" sign on the loot. It allows other scripts to see and use this data.
  3. using Statement: This is how you "equip" the module. It’s like saying, "Hey, this script needs access to the Loot Pool file."

Let's Build It

We’re going to create two files:

  1. PotionData.verse: The module that holds the potion’s stats.
  2. MainGame.verse: The main script that uses those stats to heal a player.

Step 1: Create the Module (PotionData.verse)

In UEFN, create a new Verse file named PotionData.verse. This file will act as our central database for potion info.

# PotionData.verse
# This is our "Loot Pool" file. It holds the data, but doesn't run the game logic.

# Define a module named PotionData
PotionData<public> := module:

    # We want other scripts to be able to read this variable.
    # Think of this as the "Name Tag" on the potion item.
    PotionName<public><localizes>:message = "Health Potion"

    # This is how much health it restores.
    # Like the number on a medkit.
    HealAmount<public> : int = 50

    # This is the cooldown time in seconds.
    # Like the timer on a respawn beacon.
    CooldownTime<public> : float = 10.0```

**What’s happening here?**
*   `PotionData<public> := module:`: We are creating a module called `PotionData`. The `<public>` tag means this module itself can be imported by other files.
*   `PotionName...`: We define a string variable. `<localizes>` is a tag that allows this text to be translated into different languages later (like subtitles in a cutscene).
*   `HealAmount` and `CooldownTime`: These are numbers. Because they are marked `<public>`, any script that imports `PotionData` can read these values.

### Step 2: Use the Module (`MainGame.verse`)

Now, create your main Verse file (e.g., `MainGame.verse`). This is where the game actually runs.

```verse
# MainGame.verse
# This is the "Player" script. It uses the data from the Loot Pool.

# IMPORT THE MODULE
# This is like saying "Give me access to the PotionData file."
using PotionData

# This is the main entry point for your island logic
Main := @subscribe:
    (event: GameStarted) ->
        # Let's print out the info from our module to prove it works.
        # We access the module's data using the dot notation (Module.Variable).
        Print($"Potion Name: {PotionData.PotionName}")
        Print($"Heal Amount: {PotionData.HealAmount}")
        Print($"Cooldown: {PotionData.CooldownTime} seconds")

        # Now, let's simulate healing a player using that data.
        # Imagine we have a player object here.
        # Player.Health += PotionData.HealAmount
        # Print("Player healed! Thanks to the module!")

What’s happening here?

  • using PotionData: This line is crucial. It tells Verse, "Look in the other file for PotionData." Without this, Verse won’t know what PotionData is.
  • PotionData.PotionName: We access the variable inside the module. It’s like reaching into the loot box and pulling out the item labeled "PotionName."

Step 3: Test It

  1. Save both files.
  2. Open your Island in UEFN.
  3. Press "Play" or "Preview."
  4. Check the Output Log (usually at the bottom of the editor). You should see:
    Potion Name: Health Potion
    Heal Amount: 50
    Cooldown: 10.0 seconds
    

If you see this, congratulations! You’ve successfully decoupled your data from your logic.

Try It Yourself

Now that you have the basics, try this challenge:

The Challenge: Create a new module called EnemyStats.verse that stores the health and damage of a generic "Slime" enemy. Then, modify MainGame.verse to print out the Slime’s stats using the new module.

Hint:

  1. Create EnemyStats.verse with a module: declaration.
  2. Add SlimeHealth<public> := 100 and SlimeDamage<public> := 5.
  3. In MainGame.verse, add using EnemyStats.
  4. Print EnemyStats.SlimeHealth.

Don’t forget: If you change SlimeHealth to 200 in the module file, you don’t need to touch MainGame.verse at all. The change happens automatically everywhere you use the module!

Recap

  • Modules are reusable files that hold data or logic.
  • Use the module: keyword to define them.
  • Use <public> to make variables accessible to other scripts.
  • Use using ModuleName to import and access that data in your main scripts.
  • This keeps your code organized, reduces errors, and makes updating game balance (like changing potion heal amounts) a one-step process instead of a multi-file hunt.

References

  • https://dev.epicgames.com/documentation/en-us/uefn/UE/creating-visual-effects/creating-custom-modules
  • https://dev.epicgames.com/documentation/en-us/uefn/modules-and-paths-in-verse
  • https://dev.epicgames.com/documentation/en-us/fortnite/inisland-transactions-device-template-in-fortnite
  • https://dev.epicgames.com/documentation/en-us/fortnite/in-island-transactions-best-practices-and-debugging-in-fortnite
  • https://dev.epicgames.com/documentation/en-us/fortnite/creating-a-column-with-modeling-mode-in-unreal-editor-for-fortnite
🔒

Keep going — free

You've read the intro. The rest of this lesson is free for members. Sign in to continue and track your progress.

Sign in free to continue this lesson
Pass the quiz above to chart this quest in your Journal.

Sources

/guides/creating-custom-modules
Source

Biloxi Studios original lesson

Guided course

Add this lesson to your free study plan.

🧭 The Keeper’s log

Quest complete? Chart your next heading from the 🐻 North Jungle expedition.

⛵ Take me there