Gamerules


Gamerules are a set of game-wise settings that change gameplay without creating a new mod. Gamerules can be toggled in-game when a new game is started. There are hardcoded gamerules which refer to base game logic, and scripted ones which mods can add.

Modding Gamerules

Custom toggleable gamerules can be defined in gamerules.txt file inside of the common folder. If you have no gamerules file, then create one. The selected option of each gamerule is stored in the savegame, and thus is kept persistent between restarts.

A gamerule is defined like this:

scripted_gamerule = {
    name = "test_gamerule"
    option = {
        name = "test__gameruleopt_1"
        on_select = {
            set_global_flag = rule_1
        }
        on_deselect = {
            clr_global_flag = rule_1
        }
    }
    option = {
        name = "test__gameruleopt_2"
        default_option = yes
        on_select = {
            set_global_flag = rule_2
        }
        on_deselect = {
            clr_global_flag = rule_2
        }
    }
    }

The name member is a unique string identifier for said gamerule and is mandatory. Two or more gamerules may not have the same name.

The localization key is the same as the name (in this case test_gamerule). The loc key for the description of the gamerule (Which is displayed in a tooltip) is the name plus _desc. So the desctiption loc key for this gamerule would be test_gamerule_desc.

Each gamerule may have one or more options. Each option also has a mandatory name member, which works similarly to the name of the gamerule itelf (except each option does not have a description loc key, only a name loc key). Each option name key is globally unique.

The default_option member signals which of the options is selected by default on a new save.

The on_select and on_deselect members describe a scripted effect to run when said option is either selected or deselected respectively. In the example above it will set a global flag when enabled, and clear that same flag when disabled.

The state of a gamerule can be checked with a trigger:

check_gamerule = {
    gamerule = "test_gamerule"
    option = "test_gameruleopt_1"
}_

Here, it evaluates if the gamerule with name test_gamerule is set to the option with the name test_gameruleopt_1.

There are also some hardcoded gamerules which interact with base gameplay directly which is not present in the gamerules.txt file. These can also have their selected option checked with check_gamerule trigger.

Below is a list of names of the hardcoded gamerules and their options: