Papyrus Integration - Exit-9B/MCM-Helper Wiki

Scripts can be informed when the value of a control changes by doing one of the following:

Events

Your config script (from Creating a Config Script) can implement events in order to respond to user actions. For instance, the OnSettingChange event is dispatched whenever the user changes a setting. The control must have the id property in order to receive this event.

The following events are provided by the config script.

; Event raised when an MCM setting is changed.
Event OnSettingChange(string a_ID)
EndEvent

; Event raised when a new page is selected, including the initial empty page. (Added in v1.3.0 - version code 11)
Event OnPageSelect(string a_page)
EndEvent

; Event raised when a config menu is opened.
Event OnConfigOpen()
EndEvent

; Event raised when a config menu is closed.
Event OnConfigClose()
EndEvent

Example:

Scriptname MyMod_ConfigMenu extends MCM_ConfigBase

GlobalVariable Property SliderValue  Auto
GlobalVariable Property ToggleValue  Auto

Event OnConfigInit()
    SliderValue.SetValue(GetModSettingFloat("fSliderValue:Main"))
    ToggleValue.SetValueInt(GetModSettingBool("bToggleValue:Main"))
EndEvent

Event OnSettingChange(string a_ID)
    if a_ID == "fSliderValue:Main"
        SliderValue.SetValue(GetModSettingFloat(a_ID))
    elseif a_ID == "bToggleValue:Main"
        ToggleValue.SetValueInt(GetModSettingBool(a_ID))
    endif
EndEvent

Control Action

You can also add a Papyrus action to a control to pass its value to a specified function whenever it is changed.

Use the {value} keyword to substitute the value of a control in a Papyrus function call. Note that the data type of the parameter will match the value type of the control. See Setting Types, Storage, and Persistence for the data types.

When passing a constant value to a function, the desired data type can be specified by prefixing {i}/{b}/{f}/{s} to the value. This casts the value to an int, bool, float or string, respectively.
e.g. "{i}42"

Action types:

{
  ...
  "action": {
    "type": "CallFunction",
    "form": "MCM_Demo.esp|800",
    "scriptName": "MCM_DemoScript",
    "function": "OnSliderValueChanged",
    "params": ["{value}"]
  }
},
{
  "text": "Demo Button",
  "type": "text",
  "help": "Displays a messagebox via a CallGlobalFunction action.",
  "action": {
    "type": "CallGlobalFunction",
    "script": "Debug",
    "function": "MessageBox",
    "params": ["Hello world!"]
  }
}