candlepin Posted April 5, 2018 Author Share Posted April 5, 2018 I took too long creating this response (and got distracted for a while while writing it) so PeterMartyr beat me to the real problem in your script. You need to use the 4th parameter for AddToggleOptionST if you're trying to use toggle A as the master switch for all other options. Putting all of the things above together your script can look something like this: Scriptname MIOS_MCM_quest_script extends SKI_ConfigBase ;========== ; Global Variables | ;========== GlobalVariable Property MIOS_GV_A Auto ; Master Toggle blocks all others when not enabled GlobalVariable Property MIOS_GV_B Auto ; example secondary value ;========= ; OnConfigInit | ;========= Event OnConfigInit() Pages = new string[2] Pages[0] = "Dummy Page" Pages[1] = "Options" EndEvent ;========= ; OnPageReset | ;========= Event OnPageReset(string page) ;================== ; MIOS MCM WELCOME PAGE | ;================== If (Page == "") LoadCustomContent("My File Directory") Else UnloadCustomContent() EndIf ;============= ; DUMMY PAGE | ;============= If (Page == "Dummy Page") SetCursorFillMode(TOP_TO_BOTTOM) SetCursorPosition(0) AddHeaderOption("Dummy Page") ;=========== ; OPTIONS | ;=========== ElseIf (Page == "Options") SetCursorFillMode(TOP_TO_BOTTOM) SetCursorPosition(0) AddHeaderOption("Options") int option_flag = OPTION_FLAG_DISABLED ; assume all but master toggle should be disabled by default if MIOS_GV_A.GetValue() as bool ; if master toggle is active then allow setting other values normally option_flag = OPTION_FLAG_NONE endif AddToggleOptionST("BoolAToggle", "A?", MIOS_GV_A.GetValue() as Bool) AddToggleOptionST("BoolBToggle", "B?", MIOS_GV_B.GetValue() as Bool, option_flag) ; AddToggleOptionST("BoolCToggle", "C?", MIOS_GV_C.GetValue() as Bool, option_flag) ; AddToggleOptionST("BoolDToggle", "D?", MIOS_GV_D.GetValue() as Bool, option_flag) EndIf EndEvent ;====== ; STATES | ;====== State BoolAToggle Event OnHighlightST() SetInfoText("A?") EndEvent Event OnDefaultST() MIOS_GV_A.SetValue(1) ; real default is false OnSelectST() EndEvent Event OnSelectST() if MIOS_GV_A.GetValue() as bool MIOS_GV_A.SetValue(0) Else MIOS_GV_A.SetValue(1) EndIf ForcePageReset() ; to update the option_flag value for all of the secondary options EndEvent EndState State BoolBToggle Event OnHighlightST() SetInfoText("B?") EndEvent Event OnDefaultST() MIOS_GV_B.SetValue(1) ; real default is false OnSelectST() EndEvent Event OnSelectST() If MIOS_GV_B.GetValue() as bool MIOS_GV_B.SetValue(0) Else MIOS_GV_B.SetValue(1) EndIf SetToggleOptionValueST(MIOS_GV_B.GetValue() as bool) EndEvent EndState I didn't use a property for my option_flag variable because that would recalculate the value every time you use it. Wow, this is just what I needed! I was missing two pieces of information: 1) int option_flag = OPTION_FLAG_DISABLEDI didn't know that an Int could be anything other than an integer. This was the key piece of information that I kind of alluded to in a question to one of Peter Martyr's responses. 2) ForcePageReset()Simple, but needed to update the page after changing the selection for ToggleA Thanks for the help Peter Matryr and cdcooley!! Link to comment Share on other sites More sharing options...
cdcooley Posted April 6, 2018 Share Posted April 6, 2018 OPTION_FLAG_DISABLED and the other value from the script are actually constant properties defined by the MCM base scripts so they really are just integers. There are two more tricks for keeping your code short. One is to use a helper function if all (or even most) of your options are just toggling boolean variables stored in global variables. The other is using the SKSE Localization feature (as described on the MCM Advanced Features page). Using the translation file to ensure that the strings displayed are exactly what you want and only use a single OnHighlightST() event instead of repeating it in every state. The downside for localization is that you need to provide a translation file for every language supported by the game (even if you just duplicate the English text in each of them). So an alternate version of the script could look like this: Scriptname MIOS_MCM_quest_script extends SKI_ConfigBase ;========== ; Global Variables | ;========== GlobalVariable Property MIOS_GV_A Auto ; Master Toggle blocks all others when not enabled GlobalVariable Property MIOS_GV_B Auto ; example secondary value ;========= ; OnConfigInit | ;========= Event OnConfigInit() Pages = new string[2] Pages[0] = "Dummy Page" Pages[1] = "Options" EndEvent ;========= ; OnPageReset | ;========= Event OnPageReset(string page) ;================== ; MIOS MCM WELCOME PAGE | ;================== If (Page == "") LoadCustomContent("My File Directory") Else UnloadCustomContent() EndIf ;============= ; DUMMY PAGE | ;============= If (Page == "Dummy Page") SetCursorFillMode(TOP_TO_BOTTOM) SetCursorPosition(0) AddHeaderOption("Dummy Page") ;=========== ; OPTIONS | ;=========== ElseIf (Page == "Options") SetCursorFillMode(TOP_TO_BOTTOM) SetCursorPosition(0) AddHeaderOption("Options") int option_flag = OPTION_FLAG_DISABLED ; assume all but master toggle should be disabled by default if MIOS_GV_A.GetValue() as bool ; if master toggle is active then allow setting other values normally option_flag = OPTION_FLAG_NONE endif AddToggleOptionST("BoolAToggle", "$MIOS_BoolAToggle", MIOS_GV_A.GetValue() as Bool) AddToggleOptionST("BoolBToggle", "$MIOS_BoolBToggle", MIOS_GV_B.GetValue() as Bool, option_flag) ; AddToggleOptionST("BoolCToggle", "$MIOS_BoolCToggle", MIOS_GV_C.GetValue() as Bool, option_flag) ; AddToggleOptionST("BoolDToggle", "$MIOS_BoolDToggle", MIOS_GV_D.GetValue() as Bool, option_flag) EndIf EndEvent ;============= ; Utility functions ;============= bool Function ToggleGV(GlobalVariable gv) If gv.GetValue() as bool gv.SetValue(0) return false Else gv.SetValue(1) return true EndIf EndFunction ;============= ; Shared OnHighlightST using Localization ;============= Event OnHighlightST() SetInfoText("$MIOS_DESC_"+GetState()) EndEvent ;====== ; STATES | ;====== State BoolAToggle Event OnDefaultST() MIOS_GV_A.SetValue(0) ; real default is false ForcePageReset() EndEvent Event OnSelectST() ToggleGV(MIOS_GV_A) ForcePageReset() ; to update the option_flag value for all of the secondary options EndEvent EndState State BoolBToggle Event OnDefaultST() MIOS_GV_B.SetValue(0) ; real default is false SetToggleOptionValueST(false) EndEvent Event OnSelectST() SetToggleOptionValueST(ToggleGV(MIOS_GV_B)) EndEvent EndState And the translation file would be something like this: $MIOS_BoolAToggle Label for A $MIOS_DESC_BoolAToggle Description for OnHighlightST about what the main Toggle option does $MIOS_BoolBToggle Label For B $MIOS_DESC_BoolBToggle Description for OnHighlightST about what toggle option B does And of course if you use more meaningful state names and variable names the translation file is easier to write. Unfortunately I never found a good way to avoid needing to explicitly reference each of the variables in a way that I could just use a single OnSelectST or OnDefaultST event. Link to comment Share on other sites More sharing options...
PeterMartyr Posted April 6, 2018 Share Posted April 6, 2018 Twas a pleasure to give you more information than you ask for. Cause in most states, a simple correct answer, requires the OP to reverse engineer it to see how it's works. Link to comment Share on other sites More sharing options...
Recommended Posts