sf2.settings
Settings are options the player controls in the mod settings: on/off switches, and choices that pick one of several options. Create a setting, then read it or pass it to an effect or a swap so it follows the player’s pick. Get sf2 with local sf2 = require("sf2").
sf2.settings.toggle
Section titled “sf2.settings.toggle”Create an on/off switch in the mod settings and get a handle to read or share it.
Signature: sf2.settings.toggle { id, label, description?, default?, group?, excludes?, heavy?, restart? }
Parameters
| Parameter | Type | Required |
|---|---|---|
definition |
SettingToggleDefinition |
Required |
Fields of SettingToggleDefinition
| Field | Type | Required | Meaning |
|---|---|---|---|
id |
string |
Required | 1-64 lowercase letters, digits, _ or -; unique within the mod. |
label |
string|LocalizationHandle |
Required | A string, or a text handle from sf2.text.get shown in the player’s language. 1-48 characters shown under Options > Mod settings. |
description |
string|LocalizationHandle |
Optional | A string, or a text handle from sf2.text.get shown in the player’s language. Up to 160 characters. |
default |
boolean |
Optional | Default false. |
group |
string|LocalizationHandle |
Optional | A string, or a text handle from sf2.text.get shown in the player’s language. 1-32 characters: the heading this switch is listed under on the mod’s settings page. |
excludes |
SettingHandle|SettingHandle[] |
Optional | Earlier switches that cannot be on together with this one. Up to 8. |
heavy |
boolean |
Optional | Default false. True for a switch whose effects cost a lot of GPU time: under the Performance effects preset, the game treats it as off and Options > Mod settings shows it Off and locked, keeping the choice the player made for Quality. |
restart |
boolean |
Optional | Default false. True when the mod reads this setting only while it loads: Options > Mod settings tells the player that a change shows after a restart. |
Returns: A setting handle, passed as setting to a visuals function or to sf2.settings.get.
When: Entrypoint. Register switches before the effects that use them.
local trails = sf2.settings.toggle { id = "weapon_trails", label = "Weapon trails", description = "Short trails behind fast weapon swings.", default = true,}
-- Two looks that should never stack: turning one on turns the other off.local rim = sf2.settings.toggle { id = "rim_light", label = "Rim light", group = "Lighting", default = true }local wrap = sf2.settings.toggle { id = "light_wrap", label = "Light wrap", group = "Lighting", excludes = rim }
-- Expensive and optional: left off when the player picks the Performance effects preset.local rays = sf2.settings.toggle { id = "god_rays", label = "God rays", group = "Lighting", default = true, heavy = true }label, description and group take a string or a text handle from sf2.text.get. A text handle shows in the player’s language and follows a language change; the length limits apply to its English text:
local rim = sf2.settings.toggle { id = "rim_light", label = sf2.text.get("setting.rim_light.label"), description = sf2.text.get("setting.rim_light.description"), group = sf2.text.get("group.lighting"),}The id keeps the player’s choice stable across versions, so do not rename it. Switches appear under Options > Mod settings. excludes takes switches you registered earlier; two that exclude each other cannot both default to true. If a save has both on, the earlier one stays on. For one setting with more than two values, such as a pick between three music themes, use sf2.settings.choice instead of several switches that exclude each other.
heavy = true marks a switch whose effects cost a lot of GPU time. While the player has the Performance effects preset (Options > Display > Effects, the default in the 32-bit Android build), the switch reads as off: its effects stop and sf2.settings.get returns false. Options > Mod settings then shows it as Off, faded, and the player cannot change it. The player’s own choice is kept: under Quality the switch shows it again and works as before. See Menus and settings.
A change takes effect at once: swaps and effects check the switch as they play or draw, and a swapped music track that is playing fades over to the new one. If your script reads the switch only while it loads (for example to decide what to register), set restart = true; the switch’s description under Options > Mod settings then tells the player that a change shows after a restart.
sf2.settings.choice
Section titled “sf2.settings.choice”Create a setting that lets the player pick one of several choices, and get a handle to read it or gate a swap with it.
Signature: sf2.settings.choice { id, label, description?, group?, choices, default?, restart? }
Parameters
| Parameter | Type | Required |
|---|---|---|
definition |
SettingChoiceDefinition |
Required |
Fields of SettingChoiceDefinition
| Field | Type | Required | Meaning |
|---|---|---|---|
id |
string |
Required | 1-64 lowercase letters, digits, _ or -; unique among the mod’s switches and choices. |
label |
string|LocalizationHandle |
Required | A string, or a text handle from sf2.text.get shown in the player’s language. 1-48 characters shown under Options > Mod settings. |
description |
string|LocalizationHandle |
Optional | A string, or a text handle from sf2.text.get shown in the player’s language. Up to 160 characters. |
group |
string|LocalizationHandle |
Optional | A string, or a text handle from sf2.text.get shown in the player’s language. 1-32 characters: the heading this setting is listed under on the mod’s settings page. |
choices |
SettingChoiceOption[] |
Required | 2-8 choices, in the order the picker steps through them. |
default |
string |
Optional | The id of the choice used until the player picks one. Default: the first choice. |
restart |
boolean |
Optional | Default false. True when the mod reads this setting only while it loads: Options > Mod settings tells the player that a change shows after a restart. |
Returns: A choice handle, passed to sf2.settings.get or as setting (with choice) to a swap.
When: Entrypoint. Register the choice before the swaps that use it.
local theme = sf2.settings.choice { id = "dojo_theme", label = "Dojo theme", group = "Audio", choices = { { id = "normal", label = "Normal" }, { id = "remastered", label = "Remastered" }, { id = "night", label = "Night" }, }, default = "normal",}
-- Each swap plays only while its choice is picked; "normal" has none, so the game's own track plays.for _, id in ipairs({ "remastered", "night" }) do sf2.assets.replace { music = "menu", replacement = sf2.assets.audio("audio/menu_" .. id), setting = theme, choice = id, }endThe choice appears under Options > Mod settings with your mod’s switches, as a < value > picker. The player steps through the choices in the order you list them: clicking or tapping the right half of the picker, or pressing Right, goes forward; the left half, or Left, goes back.
| Field | Required? | Meaning |
|---|---|---|
id |
Yes | 1-64 lowercase letters, digits, _ or -, unique among your mod’s switches and choices. It keeps the player’s pick across versions, so do not rename it. |
label |
Yes | 1-48 characters shown beside the picker. A string, or a text handle from sf2.text.get shown in the player’s language. |
description |
No | Up to 160 characters, shown while the picker has focus. A string or a text handle. |
group |
No | A heading (1-32 characters) to list the choice under, shared with switches of the same group. A string or a text handle. |
choices |
Yes | A list of 2 to 8 tables, in picker order. Each has an id (1-64 lowercase letters, digits, _ or -, unique in this list), a label (1-32 characters; a string or a text handle) and an optional from_switch. |
default |
No (the first choice) | The id of the choice used until the player picks one. |
restart |
No (false) |
true when your script reads the choice only while it loads: its description then says that a change shows after a restart. Swaps gated by the choice change at once without it. |
The player’s pick is stored as the choice’s id, so you can rename a label freely. Keep the ids: if a later version of your mod drops an id the player had picked, the setting reads as default again. Adding choices is safe.
Moving players over from old switches
Section titled “Moving players over from old switches”from_switch on a choice names a switch an earlier version of your mod registered with sf2.settings.toggle. A player who had that switch on, and has not picked anything in the new setting yet, starts on that choice. Stop registering the old switch; naming a switch your mod still registers is an error.
local sky = sf2.settings.choice { id = "sky", label = "Sky", choices = { { id = "day", label = "Day" }, { id = "storm", label = "Storm", from_switch = "storm_sky" }, -- was a switch },}If several old switches were on, the first matching choice in the list wins. Once the player picks a choice, the old switches no longer matter.
Where a choice works
Section titled “Where a choice works”sf2.settings.getreturns theidof the picked choice.sf2.assets.replace,sf2.world.replaceandsf2.battles.replace_previewtake it assettingtogether withchoice, theidthe swap applies to.- Visual effects (
sf2.fx) andexcludestake switches only.
The All switches row on your mod’s page turns switches on and off and leaves choices as the player set them. A choice is stored per installation, not in the save. See Menus and settings.
sf2.settings.get
Section titled “sf2.settings.get”Read the current value of a mod setting: whether a switch is on, or which choice is picked.
Signature: sf2.settings.get(setting)
Parameters
| Parameter | Type | Required |
|---|---|---|
setting |
SettingHandle |
Required |
Returns: For a switch from sf2.settings.toggle, true or false. For a choice from sf2.settings.choice, the id of the picked choice, a string.
When: After the setting is registered. The value can change while the game runs.
if sf2.settings.get(trails) then -- The player has trails on.end
if sf2.settings.get(theme) == "night" then -- The player picked the Night choice.endRead the value when you need it rather than once at load: the player can change it under Options > Mod settings at any time. A heavy switch reads as false under the Performance effects preset. A choice whose stored pick your mod no longer offers reads as its default.