Skip to content

Reading Setting Values

Conner Olsen edited this page Jun 26, 2026 · 26 revisions

Setting values are stored in EU5 variable maps. You can read them anywhere in your mod's scripted effects or triggers using the "variable_map(cmm|...)" syntax.

Basic Settings

Toggle, dropdown, numeric, and slider settings store their value in the country-scoped cmm variable map, keyed by flag:[Your_Mod_ID]__[Your_Setting_ID].

Access it with the "variable_map()" quoted scope link:

if = {
	limit = {
		"variable_map(cmm|flag:cmm_example__example_toggle)" >= 1
	}
	# Runs if the toggle is enabled
}
Setting Value
Toggle 0 = disabled, 1 = enabled
Dropdown Selected option ordinal (starting from 1)
Numeric The current numeric value
Slider The current slider value
Button No stored value (fires an effect on click)
Text No stored value (submitted text is passed as $text$ to the callback)

When reading inside a parameterized effect where the setting key comes from a macro, use a local variable as an intermediary (macros don't expand inside quotes):

set_local_variable = { name = cmm_tmp value = flag:$setting$ }
if = {
	limit = {
		"variable_map(cmm|local_var:cmm_tmp)" >= 1
	}
}

Global Settings

Global settings store their value in the global-scoped cmm variable map. Access it with "global_variable_map()":

if = {
	limit = {
		"global_variable_map(cmm|flag:cmm_example__global_example_toggle)" >= 1
	}
	# Runs if the global toggle is enabled
}

Settings List Fields

Each field in a settings list is stored in the cmm variable map with a compound key:

"variable_map(cmm|flag:[Your_Mod_ID]__[Your_Setting_ID]_i[item_number]_f[field_slot])"
  • item_number - the item number (1 through item_count).
  • field_slot - the field registration order (1 through 5). The first field you register gets slot 1, the second gets slot 2, and so on.

For example, the "enabled" bool field (slot 1) for item 3:

"variable_map(cmm|flag:cmm_example__example_list_i3_f1)"

For global settings lists, use "global_variable_map(cmm|...)" instead.

When the item number comes from a macro (e.g. inside cmm_for_each_list_item), use a local variable:

set_local_variable = { name = cmm_tmp value = flag:cmm_example__example_list_i$i$_f1 }
if = {
	limit = {
		"variable_map(cmm|local_var:cmm_tmp)" >= 1
	}
	# This item's "enabled" field is on
}

Reacting to Changes

CMF fires the cmf_on_callback on_action after any setting is changed through the UI. Hook into it only if you want to run custom logic when a setting changes.

This is the same unified callback used by alert clicks and action bar buttons. Hook into it the same way as cmf_on_mod_registration:

# In your on_action file (in_game/common/on_action/):
cmf_on_callback = {
	on_actions = {
		cmm_example_on_callback
	}
}

cmm_example_on_callback = {
	effect = {
		if = {
			limit = { var:cmf_callback = flag:cmm_example__example_toggle }
			# Runs when example_toggle changes
		}
	}
}
  • var:cmf_callback - a country variable set to the flag of the target that was interacted with. Compare it to flag:[Your_Mod_ID]__[Your_Setting_ID] to identify which setting was modified.

This works for all auto-apply setting types (toggle, dropdown, numeric, slider, button). Text settings fire their own scripted effect callback. List settings fire the on_action after cmm_apply_list_change processes the change.

Setting Aliases

You can give a setting an alias - a second variable that mirrors the main setting value. This lets you use a shorter or more meaningful name in your scripts while keeping the CMM internal name intact.

Aliases are:

  • Synced on menu open - every time CMM registration runs, the alias is set to the current value.
  • Synced on change - when the player changes the setting through the CMM UI, the alias is immediately updated (via cmf_on_callback).
  • One-way - changing the alias variable directly (e.g. change_variable) does not update the main setting.

Add cmm_sync_setting_alias in two places - your registration effect (syncs on menu open) and your cmf_on_callback callback (syncs immediately on UI change):

# In your registration effect:
your_mod_register = {
	cmm_register_bool_setting = {
		mod_id = your_mod
		setting_id = my_toggle
		tab_id = general
		group_id = settings
		default_value = 1
	}
	cmm_sync_setting_alias = {
		setting = your_mod__my_toggle
		alias = your_mod_toggle
	}
}
# In your cmf_on_callback handler (scripted effect):
your_mod_handle_callback = {
	cmm_sync_setting_alias = {
		setting = your_mod__my_toggle
		alias = your_mod_toggle
	}
}

Now var:your_mod_toggle mirrors the toggle value (0 or 1).

This also works for list fields. Pass the field map key as setting:

cmm_sync_setting_alias = {
	setting = your_mod__your_list_i1_f1
	alias = your_mod_enabled_1
}

Bool Aliases

For toggle settings, you can use cmm_sync_bool_alias instead of cmm_sync_setting_alias. It sets the alias variable when the toggle is on and removes it when the toggle is off, so you can check it with has_variable:

# In your registration effect:
your_mod_register = {
	cmm_register_bool_setting = {
		mod_id = your_mod
		setting_id = my_toggle
		tab_id = general
		group_id = settings
		default_value = 1
	}
	cmm_sync_bool_alias = {
		setting = your_mod__my_toggle
		alias = your_mod_toggle
	}
}
# In your cmf_on_callback handler (scripted effect):
your_mod_handle_callback = {
	cmm_sync_bool_alias = {
		setting = your_mod__my_toggle
		alias = your_mod_toggle
	}
}

Then check the toggle anywhere:

if = {
	limit = { has_variable = your_mod_toggle }
	# Toggle is enabled
}

cmm_sync_setting_alias also works for bools: it copies the numeric value (0 or 1) to the alias, which you read with var:alias. Use cmm_sync_bool_alias when you prefer the has_variable pattern.

Inverted Bool Aliases

cmm_sync_bool_alias_inverted works identically to cmm_sync_bool_alias but with reversed logic: it removes the alias when the toggle is on and sets it when off.

Dropdown Option Aliases

You can assign an alias to individual dropdown options. When that option is selected, a variable with the alias name is set. When a different option is selected, the alias variable is removed. This lets you check which option is active with has_variable.

Add cmm_sync_dropdown_option_alias in two places, one call per aliased option. Not all options need an alias - option 1 in this example has none.

# In your registration effect:
your_mod_register = {
	cmm_register_dropdown_setting = {
		mod_id = your_mod
		setting_id = your_dropdown
		tab_id = general
		group_id = general_values
		default_index = 1
		option_count = 3
	}
	cmm_sync_dropdown_option_alias = {
		setting = your_mod__your_dropdown
		index = 2
		alias = using_feature_b
	}
	cmm_sync_dropdown_option_alias = {
		setting = your_mod__your_dropdown
		index = 3
		alias = using_feature_c
	}
}
# In your cmf_on_callback handler (scripted effect):
your_mod_handle_callback = {
	cmm_sync_dropdown_option_alias = {
		setting = your_mod__your_dropdown
		index = 2
		alias = using_feature_b
	}
	cmm_sync_dropdown_option_alias = {
		setting = your_mod__your_dropdown
		index = 3
		alias = using_feature_c
	}
}

Then check the active option anywhere:

if = {
	limit = { has_variable = using_feature_b }
	# Option 2 is selected
}

Non-Resettable Settings

By default, the "Reset to Defaults" button resets all registered settings to their default values. To exclude a setting from reset, call cmm_set_no_reset after its registration:

cmm_register_bool_setting = {
	mod_id = your_mod
	setting_id = critical_toggle
	tab_id = general
	group_id = settings
	default_value = 1
}
cmm_set_no_reset = {
	mod_id = your_mod
	setting_id = critical_toggle
}

The setting keeps its current value when the player presses Reset to Defaults. This is intended for settings that should not be accidentally changed once configured.

  • Works with all setting types (toggle, dropdown, numeric, slider, text, settings list).
  • Works with both local and global settings.
  • The setting can still be changed manually through the UI.

Iterating List Items

CMM provides cmm_for_each_list_item to iterate over all items in a list. It calls your effect with $i$ set to each item number in the current order (respecting any reordering the player has done).

cmm_for_each_list_item = {
	setting = cmm_example__example_list
	effect = cmm_example__example_list_each_item
}

cmm_example__example_list_each_item = {
	# $i$ is the resolved item number (1-5)
	set_local_variable = { name = cmm_tmp value = flag:cmm_example__example_list_i$i$_f1 }
	if = {
		limit = {
			"variable_map(cmm|local_var:cmm_tmp)" >= 1  # "enabled" field is on
		}
		# Do something with this item
	}
}
  • setting - the composite setting key ([Your_Mod_ID]__[Your_Setting_ID]).
  • effect - the name of your scripted effect to call for each item.
  • $i$ - the stable item number (1 through item_count), not the display position. Items are visited in display order, so for an ordered list where the player has reordered to [3, 1, 2], your effect runs with $i$=3 first, then $i$=1, then $i$=2.

List Item Values

If you attached values to list items (via cmm_set_list_item_value, cmm_add_settings_list_item, or cmm_register_settings_list_from_list), the attached game object scope is available during iteration as scope:cmm_list_current_item_value:

cmm_example__example_list_each_item = {
	# scope:cmm_list_current_item_value = the attached game object scope
	set_local_variable = { name = cmm_tmp value = flag:$setting$_i$i$_f1 }
	if = {
		limit = {
			AND = {
				"variable_map(cmm|local_var:cmm_tmp)" >= 1  # enabled
				scope:cmm_list_current_item_value = building_type:fine_cloth_guild
			}
		}
		# This item is enabled and refers to the fine_cloth_guild building
	}
}

Clone this wiki locally