Skip to content

Settings that change gameplay

Use a settings-stage mod_settings! plus a control-stage read so players can toggle behavior without editing code.

src/settings.rs (or settings_mod! in lib.rs):

use factorio_rs::prelude::*;
factorio_rs::mod_settings! {
prefix = "my_mod",
startup {
casual_mode: bool = false,
}
}

This generates Settings::CASUAL_MODE and a register() entry point Factorio calls at settings load. Details: Mod settings.

use factorio_rs::prelude::*;
use crate::settings::Settings;
fn casual_mode() -> bool {
settings.startup.get_bool(Settings::CASUAL_MODE)
}
#[factorio_rs::event(OnSingleplayerInit)]
pub fn on_singleplayer_init() {
if casual_mode() {
println!("casual mode on");
} else {
println!("casual mode off");
}
}
factorio_rs::locale! {
en {
["mod-setting-name.my_mod-casual-mode"] = "Casual mode",
["mod-setting-description.my_mod-casual-mode"] = "Softer defaults for new players.",
}
}

See Locale.

Startup settings are fixed for a test run’s mod config. Assert the branch you care about after arranging the setting in Factorio’s test harness, or keep the helper pure and unit-test the decision:

fn welcome(casual: bool) -> &'static str {
if casual { "casual mode on" } else { "casual mode off" }
}
#[cfg(test)]
mod tests {
use super::welcome;
#[test]
fn welcome_respects_flag() {
assert_eq!(welcome(true), "casual mode on");
assert_eq!(welcome(false), "casual mode off");
}
}

For world-touching checks, use factorio-rs test - Testing.