Learn / Verse Basics Lesson 4 / 6

Writing and Using Functions

In this lesson you'll learn to

  • Define your own function in Verse using a name, parameters, and a return type.
  • Call (use) a function you wrote to run its code from another place.
  • Use a function with a parameter to give it different information each time you call it.
  • Connect a custom function to a real Fortnite island moment, like a player stepping on a trigger.

🎮 Why Do We Need Functions?

Imagine you're building a Fortnite island. Every time a player steps on a pressure plate, you want to:

  1. Add 10 points to their score.
  2. Play a sound.
  3. Print a message.

What if there are 20 pressure plates? You'd have to write those same 3 steps 20 times. That's exhausting! 😩

A function fixes this. Think of a function like a vending machine. You press a button (call the function), and the machine does all the work for you every time. You only have to set it up once.


🧩 What Is a Function?

A function is a named block of code that does one job. You write it once, then call it (run it) as many times as you want.

Think of it like a recipe card. The card says "make a sandwich." You follow the steps. Next time you're hungry, you grab the same card — you don't write a new recipe!


📦 What Is a Parameter?

A parameter is information you hand to a function so it can do its job. It's like telling the vending machine which snack you want. Different input → different result!

For example, imagine a function called GivePoints. You could tell it to give 10 points one time, and 50 points another time. Same function, different number!

In Verse, you write a parameter like this inside the parentheses ():

Points : int
  • Points is the name we give the information.
  • int means it's a whole number (like 5, 10, or 100). "int" is short for integer, which just means a number without a decimal.

🎁 What Is a Return Value?

Sometimes you want a function to give something back after it runs. That's called a return value.

Imagine you ask a friend, "How many lives do I have left?" Your friend counts and tells you back the answer. That answer is the return value!

In Verse, you write : int (or another type) after the parentheses to say "this function will hand back a number."

If a function doesn't need to give anything back, you just leave that part out (or use : void).


🛠️ The Parts of a Function in Verse

Here's what a function looks like, piece by piece:

FunctionName(ParameterName : type) : returnType =
    # Your code goes here, indented
  • FunctionName — what you call the function (like GivePoints).
  • (ParameterName : type) — the info you hand in.
  • : returnType — what type of thing the function gives back.
  • = — this is like saying "here comes the recipe!"
  • The indented lines below are the actual steps.

📣 Calling a Function

Calling a function means telling it to run. You just write its name and pass in any info it needs:

GivePoints(10)

That's it! The vending machine does its job. 🎉


🏝️ Connecting to Your Island

In UEFN, your Verse code lives inside a Verse Device — a special invisible gadget you place on your island. When something happens in the game (like a player steps on a Trigger device), your device can run a function.

Here's the big picture of how it works:

  1. You place a Trigger device on your island in UEFN.
  2. Your Verse device has a reference to that trigger.
  3. When the trigger fires, Verse calls your function automatically.
  4. Your function runs its steps — like printing a score message!

This is the magic of functions: the island event calls your function, and your function does all the hard work! 🚀

Keep going — free

You've read the intro. The rest of this lesson — the worked example, the hands-on exercise, the quiz, and the recap — is free for members. Sign in to continue and track your progress.

New here? The whole Verse Basics track is free with a free account — sign in to start.

Pass the quiz above to chart this quest in your Journal.
Source
Verse Island

© Biloxi Studios Inc. — original Verse Island content.

Sources & licensing

Turn this into a guided course

Add Writing and Using Functions 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.

🧭 The Keeper's log

Quest complete? Chart your next heading from the Verse Basics expedition.