forgetandeatcake978 Posted February 17, 2021 Share Posted February 17, 2021 So, I am just starting with the mcm menu, and I am trying to create a toggle option in the menu. The idea is that players can toggle between a fixed gold reward, and a leveled gold reward. The menu appears in the mcm, the page "settings" appears and my toggle option appears. But the toggle doesn't change the global variable I want it to. Scriptname FAEC_PG_MCM extends SKI_ConfigBase ; ;Global stuff ; Globalvariable property faec_pg_game1_leveledreward auto ; ;toggle states ; bool leveledrewardsval = true; ; ;OIDS (option IDS) ; int ileveledreward; ; ;Create pages ; Event OnconfigInit() Pages = new string[1] Pages[0]= "Settings" Endevent ; ; Add options to pages ; Event OnPageReset(string page) If(page=="Settings") SetCursorFillMode(Left_to_right) AddheaderOption("Maze Game") AddEmptyOption() ileveledreward=AddToggleOption("Leveled Reward", leveledrewardsval) endif endevent ; ; make options do things ; Event OnOptionSelect(int option) if(currentpage == "settings") if(option == ileveledreward) leveledrewardsval = !leveledrewardsval SetToggleOptionValue(ileveledreward, leveledrewardsval) If(faec_pg_game1_leveledreward.getvalue() == 0 ) faec_pg_game1_leveledreward.setvalue(1) else faec_pg_game1_leveledreward.setvalue(0) endif endif endif endevent This is my code. The "Globalvariable property faec_pg_game1_leveledreward auto" is given the correct global variable in the properies menu, and the global variable is "short" with value 1. The constant box is unticked. In game when I press the toggle it should change the global variable value, but it isn't. In fact to begin with I had the global variable set to 0, but I changed it to 1, saved it and in game the global variable is still displayed as 0! Any help would be great Link to comment Share on other sites More sharing options...
dylbill Posted February 17, 2021 Share Posted February 17, 2021 You can get rid of the if(currentpage == "settings") line in the OnOptionSelect event. You can also bind the option directly to the globalvariable without using a bool. ; ;Global stuff ; Globalvariable property faec_pg_game1_leveledreward auto ; ;toggle states ; ; ;OIDS (option IDS) ; int ileveledreward; ; ;Create pages ; Event OnconfigInit() Pages = new string[1] Pages[0]= "Settings" Endevent ; ; Add options to pages ; Event OnPageReset(string page) If(page=="Settings") SetCursorFillMode(Left_to_right) AddheaderOption("Maze Game") AddEmptyOption() ileveledreward=AddToggleOption("Leveled Reward", faec_pg_game1_leveledreward.GetValueInt()) endif endevent ; ; make options do things ; Event OnOptionSelect(int option) if(option == ileveledreward) If(faec_pg_game1_leveledreward.getvalue() == 0 ) faec_pg_game1_leveledreward.setvalue(1) else faec_pg_game1_leveledreward.setvalue(0) endif SetToggleOptionValue(ileveledreward, faec_pg_game1_leveledreward.GetValueInt()) endif endevent For easier MCM creation, check out my mod MCM Creator: https://www.nexusmods.com/skyrim/mods/106620. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted February 17, 2021 Share Posted February 17, 2021 I would actually recommend getting into the habit of using local variables to track the users selections throughout the MCM menu. Then use the OnConfigClose to register for a single update with a short duration. The OnUpdate event would then be where all the global variables are set, quests are started, etc. Why? Some things cannot process while the menu is up and must wait for it to close. While this might not cause an immediate problem for the current menu, it can cause an issue with following menus. I would also recommend learning how the states feature works with the MCM menu. It allows for grouping all the events for a given option in one spot. Here is my take on your menu: Scriptname FAEC_PG_MCM extends SKI_ConfigBase ;Global stuff Globalvariable property faec_pg_game1_leveledreward auto ;toggle states bool leveledrewardsval = true; ;Initiate stuff - i.e. Create pages Event OnconfigInit() Pages = new string[1] Pages[0]= "Settings" Endevent Event OnConfigClose() RegisterForSingleUpdate(0.1) ; waits for menu to close before counting down timer EndEvent ; Add options to pages Event OnPageReset(string page) If page == Pages[0] ;why re-type the string when you can compare to the array entry SetCursorFillMode(Left_to_right) AddheaderOption("Maze Game") AddEmptyOption() AddToggleOptionST("RewardState","Leveled Reward",leveledrewardsval) ;ileveledreward=AddToggleOption("Leveled Reward", leveledrewardsval) endif endevent ; State blocks State RewardState Event OnSelectST() leveledrewardsval = !leveledrewardsval SetToggleOptionValueST(leveledrewardsval) EndEvent Event OnDefaultST() leveledrewardsval = false SetToggleOptionValueST(leveledrewardsval) EndEvent Event OnHighlightST() SetInfoText("OFF: Fixed reward \n ON: Leveled reward") EndEvent EndState ;finally do everything once menu has been exited and the timer finished Event OnUpdate() If leveledrewardsval == false faec_pg_game1_leveledreward.setvalue(0.0) Else faec_pg_game1_leveledreward.setvalue(1.0) EndIf EndEvent Link to comment Share on other sites More sharing options...
dylbill Posted February 17, 2021 Share Posted February 17, 2021 I agree using OnConfigClose is better for using other functions such as starting and stopping quests, but if using a globalvariable I prefer to set those directly with the menu options. This is because using local variables as well creates more work in writing the script, and if you're setting the globalvariable directly you can immediatly see if it's working, (if you've set up and filled the globalvariable properties correctly.) Also a side note, using globalvariables is great because you can use them in conditions in the creation kit, but, if you don't plan on using them in the creation kit, I would recommend using only script properties instead because this again means you have to do less work, (you don't have to create globalvariable forms in the CK) and you can still access them from other scripts in your mod. Link to comment Share on other sites More sharing options...
forgetandeatcake978 Posted February 18, 2021 Author Share Posted February 18, 2021 I would actually recommend getting into the habit of using local variables to track the users selections throughout the MCM menu. Then use the OnConfigClose to register for a single update with a short duration. The OnUpdate event would then be where all the global variables are set, quests are started, etc. Why? Some things cannot process while the menu is up and must wait for it to close. While this might not cause an immediate problem for the current menu, it can cause an issue with following menus. I would also recommend learning how the states feature works with the MCM menu. It allows for grouping all the events for a given option in one spot. Here is my take on your menu: Scriptname FAEC_PG_MCM extends SKI_ConfigBase ;Global stuff Globalvariable property faec_pg_game1_leveledreward auto ;toggle states bool leveledrewardsval = true; ;Initiate stuff - i.e. Create pages Event OnconfigInit() Pages = new string[1] Pages[0]= "Settings" Endevent Event OnConfigClose() RegisterForSingleUpdate(0.1) ; waits for menu to close before counting down timer EndEvent ; Add options to pages Event OnPageReset(string page) If page == Pages[0] ;why re-type the string when you can compare to the array entry SetCursorFillMode(Left_to_right) AddheaderOption("Maze Game") AddEmptyOption() AddToggleOptionST("RewardState","Leveled Reward",leveledrewardsval) ;ileveledreward=AddToggleOption("Leveled Reward", leveledrewardsval) endif endevent ; State blocks State RewardState Event OnSelectST() leveledrewardsval = !leveledrewardsval SetToggleOptionValueST(leveledrewardsval) EndEvent Event OnDefaultST() leveledrewardsval = false SetToggleOptionValueST(leveledrewardsval) EndEvent Event OnHighlightST() SetInfoText("OFF: Fixed reward \n ON: Leveled reward") EndEvent EndState ;finally do everything once menu has been exited and the timer finished Event OnUpdate() If leveledrewardsval == false faec_pg_game1_leveledreward.setvalue(0.0) Else faec_pg_game1_leveledreward.setvalue(1.0) EndIf EndEvent I am following a youtube tutorial for this, and I think it was made before states was a thing. So thank you for pointing them out! The code works now, although I am still not sure what was wrong before. Well, I'll read up on states anyway Link to comment Share on other sites More sharing options...
IsharaMeradin Posted February 18, 2021 Share Posted February 18, 2021 Also a side note, using globalvariables is great because you can use them in conditions in the creation kit, but, if you don't plan on using them in the creation kit, I would recommend using only script properties instead because this again means you have to do less work, (you don't have to create globalvariable forms in the CK) and you can still access them from other scripts in your mod.Unless one wants the mod to also function without SkyUI and the MCM menu, then global variables would be necessary as the user could make their "choices" by directly changing the global variable within the console. Also, if the mod was originally designed to be adjusted via the console then using the existing global variables in an added MCM menu makes sense. Just another way to demonstrate that there are often times several ways to achieve the same goal. It all depends on preference, target audience and the pre-existing content being worked with. Link to comment Share on other sites More sharing options...
Recommended Posts