Creating Functions
Organize and reuse your game logic by creating modular functions.
A Function is a reusable sequence of actions that you can "call" from other places in your game logic, such as from an event or even from another function. They are essential for keeping your game logic organized, efficient, and easy to manage.
You can create and manage functions in /editmap -> Functions.
Why Use Functions?
Imagine you have a complex set of actions that you need to run in many different places, like giving a player a set of starting gear and teleporting them to a spawn point. Instead of copying and pasting those actions into every single event, you can create a single function called SetupPlayer and then just use the Call Function action to run it wherever you need it.
This means if you ever want to change the starting gear, you only have to edit it in one place!
Creating a Function
- Navigate to the Functions menu in
/editmap. - Click "Create Function".
- Give your function a unique and descriptive name.
- You'll be taken to the Function Edit Menu where you can:
- Change the Icon: Helps you identify it in menus.
- Set a Description: Reminds you what the function does.
- Add Actions: This is where you build the sequence of actions that the function will perform.
Calling a Function
To execute a function, you use the Call Function action. You can add this action to:
- Any region event.
- A custom item's click/hold event.
- A custom GUI's button click event.
- Even inside another function (but be careful not to create infinite loops!).
Automatic Execution (Timers)
Functions can also be set to run automatically on a timer, without needing to be called by an event. This is perfect for game loops, countdowns, or periodic checks.
In the Function Edit Menu, you can configure:
- Automatic Execution: Set how often the function should run, in ticks (20 ticks = 1 second). A value of
0disables automatic execution. - Execution Mode:
ONCE: The function runs once for the entire map at the specified interval. Useful for global logic like checking a round timer.PER_PLAYER: The function runs separately for every single player in the map at the specified interval. This is useful for things like custom potion effects, regenerating shields, or checking a player-specific property regularly.