How mods work
Every other page of this wiki leans on a few ideas. This page explains each one once, in plain terms. You do not have to memorise it. Come back when a word is unfamiliar; the glossary at the end links each term to the page that uses it.
What a mod is
Section titled “What a mod is”A mod is a folder (or a ZIP of one) with a mod.toml file at its top and,
usually, some of the following:
yourname.mymod/ mod.toml the manifest: who you are and what you need scripts/main.lua the entry script: your Lua code localizations/ text in each language (eng.toml, pol.toml, ...) assets/ your pictures, sounds and models weapons/ weapons described as data (see the Weapons guide) movesets/ move edits made with the in-game Moveset LabYou only need the parts your mod uses. A reskin may have no script at all.
The manifest
Section titled “The manifest”mod.toml is a plain text file in TOML, a simple
key = value format. Eclipse reads it before it runs any Lua.
schema = 1id = "yourname.training"name = "Training Equipment"version = "1.0.0"authors = ["Your Name"]entrypoint = "scripts/main.lua"
[[dependencies]]id = "core"version = ">=2.0 <3.0"| Field | Required? | Meaning |
|---|---|---|
schema |
Yes | The manifest format. Always 1. |
id |
Yes | Your mod’s permanent identity: lowercase letters, digits, ., _ or -, no spaces. core is reserved. Choose it before you share the mod and never change it. |
name |
Yes | The name players see in the mod menu. |
version |
Yes | Your release version, such as 1.0.0. Raise it when you publish changes. |
authors |
Yes | A list of one or more names. |
entrypoint |
No | The Lua file to run, inside scripts/. Leave it out for a mod made only of data files. |
save_binding |
No | "none" (default) or "required". With "required", each campaign save remembers whether your mod was on when it was created. See Saving and options. |
Some practical rules for the file:
- Put every main field above the first
[[dependencies]]line. TOML treats everything after that line as part of the dependency. - Strings go in
"double quotes". Whole numbers and lists in[square brackets]work; a#starts a comment. - Mistakes are reported with the file and line number. Unknown fields and repeated keys are errors.
Changing name only changes the label. Changing id makes a different mod, and
items players already own from the old ID become unavailable.
Dependencies
Section titled “Dependencies”A dependency names another mod whose content yours refers to. Whenever you use
something owned by another mod, including the base game (core), add a
[[dependencies]] block with its id and a version range. ">=2.0 <3.0"
means “at least 2.0.0 and below 3.0.0”; list several conditions separated by
spaces. Use =, >, >=, < or <= (not npm-style ^ or ~). There is no
Mods/core folder: the base game is built in.
A dependency makes the other mod load first, and turning your mod on turns the dependency on as well. Missing or incompatible dependencies show under Details in the mod menu.
Data-only mods
Section titled “Data-only mods”A mod without an entrypoint runs no Lua. It can still ship translations in
localizations/, move edits in movesets/*.json and weapons in
weapons/*.json. The in-game Moveset Lab and Weapon Workshop save mods this way.
A mod can have both an entry script and data files; the data files load first.
What your mod uses
Section titled “What your mod uses”You do not declare permissions. The game works out what your mod uses, such as adding content, changing combat or saving data, and lists it in the mod menu so players can see it. Only dependencies are declared.
IDs and handles
Section titled “IDs and handles”Owners and IDs
Section titled “Owners and IDs”Every piece of content has an owner: the mod that defined it. This keeps two
mods from clashing when both call something blade.
- A local ID is the short name you give your own content, like
training_blade. - A qualified ID adds the owner and a path:
tutorial.blade:items/weapon/training_blade. - Content from the base game is owned by
core:core:items/weapon/weapon_katana.
Write a bare name for your own content and a core: (or other mod’s) prefix for
anyone else’s. Without the prefix an ID always means your mod, so
sf2.items.get("items/weapon/weapon_katana") looks for your own katana and
fails. Copy base-game IDs from the core catalog instead
of guessing them from display names.
Asset IDs are paths inside your mod’s assets/ folder without the last
extension. assets/sprites/weapon.asset becomes sprites/weapon.
Handles
Section titled “Handles”Lookups and register functions return a handle: a value that stands for
one thing of one kind. You cannot hold the game’s real objects in Lua; a handle
is how you refer to them.
local katana = sf2.items.get("core:items/weapon/weapon_katana") -- an item handlelocal icon = sf2.assets.sprite("sprites/weapon") -- a sprite handlelocal blade = sf2.items.register { category = "weapon", ... } -- the new item's handleHandles are not interchangeable: a sprite handle cannot stand in for an item handle. Wherever a field asks for a handle, you can usually write the ID string instead. These two do the same thing:
sf2.fighters.register { id = "rival", fighter = sf2.fighters.get("core:warrior-templates/man_kungfu") }sf2.fighters.register { id = "rival", fighter = "core:warrior-templates/man_kungfu" }For your own content the short local name is enough. Keep a handle in a variable when you refer to the same thing many times.
Three verbs
Section titled “Three verbs”Most content functions follow one pattern:
| Verb | What it does | Example |
|---|---|---|
register |
Makes something new. | sf2.items.register { ... } |
patch |
Changes something that already exists. | sf2.items.patch { item = ..., price = ... } |
get |
Returns a handle to something that exists. | sf2.perks.get("core:perks/perk_cobra") |
Functions take a single table. Mistakes in that table, such as a wrong field, a
wrong type or an unknown ID, raise a clear error message that names the field.
Only a few functions whose names start with try_ can fail for reasons outside
your control and return nil and a reason instead.
When your code runs
Section titled “When your code runs”A mod has two kinds of code.
Definitions describe what exists: items, perks, battles and so on. They run from your entry script when Eclipse loads the enabled mods. Keep the entry script to registrations and lookups, so every load produces the same content. The title screen loads mods once, just to show their equipment on the sparring fighters, and starting a campaign or versus match loads them again. Registration is all-or-nothing: if one definition is invalid, the whole mod is rejected and none of its content appears.
Registering something does not hand it to the player. A weapon needs a shop listing or a reward, and a battle needs a map position.
Callbacks are functions you give to the API so the game calls them later, for example when a round starts or a hit lands. They hold your custom behaviour. A callback usually lives inside a behaviour, a reusable table of callbacks that you attach to a perk, an enchantment, a fight rule or an actor. Inventing a field that is not a documented callback does nothing, because the game never calls it.
-- Inside a behaviour table:on_round_begin = function(params, fighter, event) fighter:change_health(params.heal)endThe fighter a callback receives only works until the callback returns, so do not store it. If a callback raises an error, the error is reported and other mods are unaffected, but anything it already did to the game stays done.
Where to keep a value
Section titled “Where to keep a value”| You need | Use |
|---|---|
| A number that configures a perk, enchantment or rule | The behaviour’s parameters. |
| A value that changes during a round or fight | The behaviour’s state. |
| Progress that must last between sessions | Saved state. |
| An opponent’s decision memory | The memory table in an AI tactic. |
A plain Lua variable at the top of a file is handy for linking definitions, but it is not saved and starts fresh when the mods load again.
Keep IDs stable
Section titled “Keep IDs stable”Saves refer to your content by ID. Once players use your mod, keep your mod id
and every content ID the same. If you must retire one, use
sf2.items.retire so saved copies still
resolve.
Some changes can only have one owner, such as patching the same move or replacing the same asset. If two enabled mods claim the same thing, the second one fails to load. Order on disk never picks a winner. See Sharing and combining mods.
Write to the log
Section titled “Write to the log”The four log functions write a message tagged with your mod’s ID, which is the
easiest way to see what your script is doing. Pick the level that fits:
debug for detail,
info for milestones,
warn for problems you recovered from and
error for failures. Each takes one string;
convert numbers with tostring().
sf2.log.info("Registered " .. sf2.mod.id)sf2.mod.id, sf2.mod.name and sf2.mod.version hold values from your
manifest and are read-only. Logging an error does not stop your script. Use
Lua’s error("reason") for that. An uncaught error in your entry script makes
the mod fail to load. Troubleshooting shows where the log
lives and how to read it.
Glossary
Section titled “Glossary”Mod. A folder or ZIP with a mod.toml. See Make your first mod.
Manifest. The mod.toml file. See The manifest.
Core. The base game, treated as a mod with the ID core. Everything it ships
(weapons, perks, fights, sounds, icons) is listed in the
core catalog.
Dependency. Another mod your mod uses. See Dependencies.
ID, handle. The name of a piece of content, and the value a function returns for it. See IDs and handles.
Asset. A file your mod ships under assets/: a picture, sound or model.
See Reskin the game.
Sprite, texture, atlas. A texture is a PNG. A sprite is a named piece of a texture with a pivot and other settings. An atlas packs many sprites into one picture. See Reskin the game.
Localization key. The name of a text entry that can be translated. See Reskin the game.
Item, subtype. An item is a weapon, armor, helm, ranged weapon, magic or
consumable. A weapon’s subtype (such as Katana) is its move family. See
Weapons.
Perk, enchantment. A perk is an ability a player learns or an opponent carries. An enchantment is an effect on one item, added at the forge. See Perks and enchantments.
Behaviour, callback. A reusable table of callbacks, and one such function the game calls when something happens. See Combat scripting.
Rule. A condition or effect attached to a fight, such as “no perks” or hot ground. See Battle rules.
Fighter, opponent, tactic. A fighter is a reusable character blueprint. An opponent is the character a fight uses. A tactic is the AI that picks the opponent’s actions. See Story battles and AI.
Page, battle, fight. A page of the story map holds battles. A battle is a node the player enters. A fight is one match inside it, with its own opponents, rules and rewards. See Story battles.
Mode. An ordered series of fights, such as an event or a raid. See Underworld and modes.
Move, window, frame. A move is an animation plus the rules for when it starts, what it hits and what follows. A window is a range of frames in which it has a property. A frame is one game tick. See Moves.
State. Values a behaviour remembers for a round, a fight, or in the save. See Saving and options.
Forge. The place where players enchant equipment. See Forge and economy.