Mod settings
Use mod_settings! in a settings-stage module to define startup or runtime
settings. The macro expands to:
- a
Settingstype withpub constname strings pub fn register()that extends Factoriodatawith setting prototypes
use factorio_rs::prelude::*;
factorio_rs::mod_settings! { prefix = "msr",
startup { casual_mode: bool = false, adjacency_enabled: bool = true, }
// runtime_global { ... } // runtime_per_user { ... }}Naming
Section titled “Naming”| Rust field | Const | Factorio setting name |
|---|---|---|
casual_mode |
Settings::CASUAL_MODE |
msr-casual-mode (with prefix = "msr") |
Stage keywords use underscores (runtime_global). Generated Lua uses Factorio’s hyphenated strings ("runtime-global").
| Rust type | Prototype |
|---|---|
bool |
bool-setting |
integer types (i32, u64, …) |
int-setting |
f32 / f64 |
double-setting |
&str / String |
string-setting |
Reading in control
Section titled “Reading in control”use factorio_rs::prelude::*;use crate::settings::Settings;
const CASUAL_MODE: bool = settings.startup.get::<bool>(Settings::CASUAL_MODE);Put locale strings for setting names/descriptions in a locale! block - see Locale.
Reading values in Lua terms
Section titled “Reading values in Lua terms”settings.startup.get::<bool>(Settings::CASUAL_MODE)lowers roughly to settings.startup["msr-casual-mode"].value.
Setting / API structs often use ..Default::default() so only the fields you set appear in the Lua table - see Language support.