Skip to content

sf2.debug

Testing helpers. Add your own buttons to the debug menu outside fights, shown only in the Unity editor and development builds. Get sf2 with local sf2 = require("sf2").

Add a button to the debug menu outside fights, for testing your mod: replay a tutorial, jump to a state, open a screen.

Signature: sf2.debug.action { id, label, run }

Parameters

Parameter Type Required
definition DebugAction Required

Fields of DebugAction

Field Type Required Meaning
id string Required 1-64 letters, digits, _ or -, unique in your mod. The same id again replaces the action.
label string Required The button caption, up to 64 characters.
run fun() Required Called when the button is pressed.

Returns: Nothing. An invalid definition is an error.

When: Entrypoint, while your mod loads. The button shows only in the Unity editor and development builds.

local guide_seen = "intro_seen" -- a state field your mod registered
sf2.debug.action {
id = "replay_intro",
label = "Replay the intro",
run = function()
sf2.state.set { [guide_seen] = false }
sf2.log.info("The intro shows again on the next map visit.")
end,
}

Press F1 anywhere outside a fight (the title screen, the map, the shop…) to open the debug menu. It lists RELOAD MODS and then every mod’s actions, one button each; pressing one closes the menu and calls its run(). The menu also closes with F1, Esc or its X.

  • id (required): 1 to 64 letters, digits, _ or -, unique in your mod. Registering the same id again replaces the earlier action.
  • label (required): the button’s caption, up to 64 characters. Players never see it, so plain words are fine.
  • run (required): a Lua function with no arguments. It runs between frames, as a map button’s handler does, so it may open screens, start fights with sf2.story.start_fight (on the map) or change your saved state. An error in it is written to the log and shown at the foot of the menu; the game goes on.

A mod registers at most 16 actions. Release builds accept the call, so the same mod runs everywhere, but never show or run the buttons. Use actions for testing only: anything players should do belongs in your own menus. A reload (F9) registers them again from your fresh script.