Weird. I just plunked your code as is in my favourite colour mod and it just works... (I mean your previous version without the model.)
Odd. Well just for the fun of it, here's my full code: Code: $(function () { var settings = decode(localStorage.settings); var rules = settings.LUnitNames_Rules_options; var selected = settings.LUnitNames_Rules; if (!rules) { rules = new Array(); } if (!selected) { selected = new Array(); } model.addSetting_MultiSelect("Rules to apply to units for renaming:", "LUnitNames_Rules", "UI", rules, 0, 10, "Unit renaming rules"); model.addSetting_Button("", "Add new rule", "UI", "model.LUnitNames_Add", "Unit renaming rules"); model.addSetting_Button("", "Edit selected rule", "UI", "model.LUnitNames_Edit", "Unit renaming rules"); model.addSetting_Button("", "Remove selected rule", "UI", "model.LUnitNames_Remove", "Unit renaming rules"); console.log("LUnitNames: Settings GUI setup"); }); model.LUnitNames_Add = function () { var settings = decode(localStorage.settings); var rules = settings.LUnitNames_Rules_options; rules.push('Original Unit Name -> Custom Unit Name'); console.log('LUnitNames: Added'); } model.LUnitNames_Edit = function () { console.log('LUnitNames: Editing'); } model.LUnitNames_Remove = function () { var settings = decode(localStorage.settings); var rules = settings.LUnitNames_Rules_options; var selected = settings.LUnitNames_Rules; rules.splice(rules.indexOf(selected[0]), 1); console.log('LUnitNames: Removed'); } Nothing seems wrong to me...
That's really strange. It seems to be a jQuery-thing? Replace Code: $(function () { by Code: (function () { and also replace Code: }); by Code: })(); Then it works, but I don't know why...
Theory for the "why": Assuming your mod is run as a pamm ui mod. PA itself does something like this: $(function() { <<PA code defines model and stuff>> <<load ui mods here>> <<bind ko>> }); So this enables mods to modify the model before it is bound. If you modify the model after it is bound it wont have any effects. I dunno the exact definition of $(function()); but I think it is kind of like an on load callback. So it probably adds the given function to the end of the list of functions that is called on document load. So it will be executed after that on load function of PA, after knockout has already been bound. => Modifications to the knockout model wont have effects. So generally PA UI mods should never use $(...), as they can assume that they are run in the perfect sweet spot (in document on load, after the PA model definition before the knockout bind) by PA already.
Ah, good theory. I'll take it to be true. There is a reference to $(function()) in orfjackal's thread about being a good JavaScript citizen. He claims you should only use it for DOM operations, which happens after the document is loaded, I think. So you are probably spot on.
I'm having another issue. Basically whenever I sort an array in the setting for the MultiSelect's options it displays it as a CSV list instead of multiple entries. I've done all sorts of checks and things in code and through the debugger and nothing seams to work. Thanks in advance!
Sure, the simplest thing I tried was using this line in the debugger and then restarting it: Code: window.localStorage.LUnitNames_Rules_options = ["Item1", "Item2"] That appeared as "Item1,Item2" on one line. Here's the full code: (I've added a LOT of checks to try and fix this.) Code: (function () { if (window.localStorage.LUnitNames_Rules_options.length == 0) { model.addSetting_MultiSelect("Rules to apply to units for renaming:", "LUnitNames_Rules", "UI", null, 0, 10, "Unit renaming rules"); } else if (window.localStorage.LUnitNames_Rules_options instanceof Array) { model.addSetting_MultiSelect("Rules to apply to units for renaming:", "LUnitNames_Rules", "UI", window.localStorage.LUnitNames_Rules_options, 0, 10, "Unit renaming rules"); } else { model.addSetting_MultiSelect("Rules to apply to units for renaming:", "LUnitNames_Rules", "UI", [window.localStorage.LUnitNames_Rules_options], 0, 10, "Unit renaming rules"); } model.addSetting_Button("", "Add new rule", "UI", "model.LUnitNames_Add", "Unit renaming rules"); model.addSetting_Button("", "Edit selected rule", "UI", "model.LUnitNames_Edit", "Unit renaming rules"); model.addSetting_Button("", "Remove selected rule", "UI", "model.LUnitNames_Remove", "Unit renaming rules"); $("body").html($("body").html().replace("data-bind=\"options: LUnitNames_Rules_options, selectedOptions: LUnitNames_Rules\"", "data-bind=\"options: LUnitNames_Rules_options, selectedOptions: LUnitNames_Rules\" style='width: 100%;'")); console.log("LUnitNames: Settings GUI has been setup"); })(); model.LUnitNames_Add = function () { if (!window.localStorage.LUnitNames_Rules_options) { window.localStorage.LUnitNames_Rules_options = ["Original Unit Name > Custom Unit Name"]; } else { var array = window.localStorage.LUnitNames_Rules_options; if (!(array instanceof Array)) { window.localStorage.LUnitNames_Rules_options = [array, "Original Unit Name > Custom Unit Name"]; } else { window.localStorage.LUnitNames_Rules_options = array.push("Original Unit Name > Custom Unit Name"); } } console.log("LUnitNames: Added"); console.log(window.localStorage.LUnitNames_Rules_options); } model.LUnitNames_Edit = function () { console.log("LUnitNames: Editing"); } model.LUnitNames_Remove = function () { if (window.localStorage.LUnitNames_Rules) { var array = window.localStorage.LUnitNames_Rules_options; if (!(array instanceof Array)) { window.localStorage.LUnitNames_Rules_options = new Array(); } else { window.localStorage.LUnitNames_Rules_options = array.splice(array.indexOf(window.localStorage.LUnitNames_Rules[0]), 1); } } console.log("LUnitNames: Removed"); console.log(window.localStorage.LUnitNames_Rules_options); }
change Code: window.localStorage.LUnitNames_Rules_options = <array> to Code: model.LUnitNames_Rules_options(<array>) The only value that is stored in localStorage is the selected value(s): window.localStorage.LUnitNames_Rules. The settings themselves are stored in the KO model.
Some bug reports regarding the slider: When sliding all the way to zero, it assumes that there is no value and will set it to the default value given by initialSettingValue Pressing "Restore Default" and using the slider gives a TypeError: "Uncaught TypeError: Property 'undefined' of object #<SettingsViewModel> is not a function"
I am here to ask for end user troubleshooting. I can not get PAMM to install settings manager. Anything I try to install that requires it asks to install it first, when I click for it to install it first it stalls (as it does when trying to directly install it). Deleting and reinstalling PAMM didn't help either. It had an update that wouldn't push, wouldn't update and just stalled, so I deleted mod and tried reinstall mod, still stalls to install indefinitely, and if I try to enable a mod requiring it I get a error that I cannot enable it without settings manager. Any ideas what all this is about? Is it possibly the new update and the link in the PAMM is bad, or...? EDIT: Eh shoot, it broke my whole game (new game menu is greyed webpage boxed and won't click anything after that point), so I deleted PA folder and ran launcher to re-install. Might fix mod problem too, who knows.