Go to Page... |
Thread Tools | Display Modes |
01/25/16, 02:35 AM | #1 |
|
Having issues creating an account-wide settings toggle
Hi, I'm having trouble create an 'account-wide settings' toggle for one of my addons, well actually I've got it working but its causing weird behavior with the colorpicker controls and some of the other controls, and I'm hoping someone can help me figure out what I'm doing wrong, here is some scippets of how I'm accomplishing the accountwide toggle:
When my addon loads here is how I load the settings: Lua Code:
and here is how my 'Account-Wide' toggle is setup (using libaddonmenu): Lua Code:
Just for reference here is how the Colorpicker is setup: Lua Code:
I'm using SimpleXPBar.CurSV to reference my settings through-out the rest of the code, and the issue I'm having with the colorpicker is that it keeps flipping back and forth between 2 different color settings everytime I click it, I have a feeling this has to do with how lua is referencing the object but I cant figure what its doing in this case. I've already searched around the forums and google trying to find some sample of how to create a accountwide toggle correctly but I ended up looking at how Destinations and MasterMerchant do it and trying something similar. Any suggestions on a better way of implementing this or a fix would be appreciated. |
01/25/16, 04:52 AM | #2 |
|
What I see at the first glance is this
Lua Code:
Doesn't that mean you use AWSV to save new changes but copy the data from CharSV (that didn't change) over that every time you reload UI? That would reset it to whatever is in CharSV. But maybe ZO_DeepTableCopy is the other way round, don't know. Edit: Either way I think it has to be the ZO_DeepTableCopy function, my solution was pretty much the same, just without copying tables around (why would you do that anyways?). Lua Code:
Last edited by coolmodi : 01/25/16 at 05:26 AM. |
01/25/16, 06:20 AM | #3 | ||
|
|
||
01/25/16, 06:45 AM | #4 |
|
I'm pretty much still a noob in programming, but as I understand it LUA will always reference tables, but "copy" other values.
Lua Code:
There's also something called metatables that can change the behavior of tables, ZO_DeepTableCopy ignores them, maybe that messes something up. In GroupDamage I used a custom deepcopy function because I didn't know the ZOS one existed and only because of that even stumbled over this topic. Maybe that's worth a try? Lua Code:
But again, I'm really no pro here, and maybe the error is somewhat completely different that we both just don't see |
01/25/16, 07:55 AM | #5 |
While reloading the UI when you toggle the checkbox may solve the problem, it makes for a horrible user experience. Especially when there are multiple settings that each want to reload the ui for themselves, so please use it only as a last resort when there is absolutely no other way to get around it and even then, consider adding a reload ui button instead of automatically reloading it. This advice is also meant for other authors that use forced UI reloads.
As for your problem, I think there are three issues. 1) When you replace the currently used variables in your set function you also need to inform LAM that something changed, so that it can render the changes in its controls. This can be done by firing the "LAM-RefreshPanel" callback: Lua Code:
2) ZO_SavedVars is a highly complex object. I am not sure if ZO_DeepTableCopy is enough to replace the values correctly. I don't personally use ZO_SavedVars, so correct me if I am wrong, but I think the right way to accomplish what you want is to just create a new ZO_SavedVars object and pass the values that need to be copied as defaults. 3) LAM may call setFunc more often than necessary (not 100% sure, but it might happen), so you should check if something changed before doing your copy routine. With all of these things considered, it should look something like this: Lua Code:
|
|
01/25/16, 08:42 AM | #6 | |
|
He should just make a function himself that sets all settings to the ones from the other SV and doesn't change the tables. That way it would work for sure. And yes, the reload in my code there isn't needed, I could just change the reference and it should work fine. Last edited by coolmodi : 01/25/16 at 08:46 AM. |
|
01/25/16, 08:53 AM | #7 |
Ah right. Didn't see that when glancing over the source of ZO_SavedVars.
It seems to always wipe data when version is nil, so maybe you could use that to wipe it and then call it again with the correct version for copying? |
|
01/25/16, 08:57 AM | #8 |
|
|
01/25/16, 02:49 PM | #9 | ||
|
Apparently the issue was unrelated to ZO_DeepTableCopy, I must not have been paying attention when I wrote the colorpicker tables heres what the problem was:
Lua Code:
I still can't get unpack to work though, it just returns white (or probably nil), does my color table have to look a certain way? Lua Code:
as for:
And heres what is working for an account-wide toggle if anyone wants to know: Lua Code:
checkbox: Lua Code:
I'm still going to see if I can get rid of SimpleXPBar.accountwide_settings because it seems redundant, (I was having problems getting settings to stick before using only two SavedVars). Thanks for the info and suggestions posted coolmodi, sirinsidiator, they'll definitely help. Last edited by Terrillyn : 01/25/16 at 02:57 PM. |
||
01/25/16, 03:07 PM | #10 |
Unpack requires a numerically indexed table:
Lua Code:
|
|
01/25/16, 06:32 PM | #11 |
|
I still cant get these accountwide settings to work the way I want.
there seems to be something weird going on with the references, if I try to change a an accountwide setting via console (SimpleXPBar.AWSV.textbar.text = "Hello World") or even using a function, none of the settings are updated in the live tables or saved tables, its making it utterly confusing. I have also tried using coolmodi's deepcopy and its not working, I've also tried this: Lua Code:
All I want to do is overwrite the values in one SavedVars with another while still letting them both save seperately, no references just values, this is driving me crazy, what am I doing wrong? |
01/25/16, 07:02 PM | #12 |
|
!! I think I may have come up with a solution finally, I'll need to test it abit more but its working so far.
here it is checkbox Lua Code:
At playerload Lua Code:
In this case I don't need a deepcopy it seems, since ZO_SavedVars will copy values from the default arg. |
01/25/16, 07:05 PM | #13 | |
|
|
|
01/25/16, 08:22 PM | #14 |
|
Well I spoke too soon, it wouldn't let me set accountwide settings when I did that, seems nothing I try lets me copy over another table, aside from writing a large function to manually copy over all the vars.
For now I'll just keep character and account settings in separate SavedVars, this means the user should enable the Account-Wide toggle before making any changes. checkbox Lua Code:
At playerload Lua Code:
|
01/26/16, 01:07 AM | #15 |
If working with ZO_DeepTableCopy, the resulting table is not referenced by the saved variable. => not serialized to disk.
The questions are: 1. What is the expected behavior if you switch from char to account? Current settings taken over? Or switching to account settings? 2. What is the expected behavior if you switch from account to char? Current settings taken over? Or switching to char settings what ever they were? I would try this (untested ): At addon load (EVENT_ADDON_LOADED): Lua Code:
Checkbox: Lua Code:
|
|
01/26/16, 01:55 AM | #16 | ||||
|
Last edited by Terrillyn : 01/26/16 at 02:05 AM. |
||||
01/26/16, 02:18 AM | #17 |
Maybe the simplest solution is that the get-functions return CurSV, while the set-functions always set the value in CharSV and optional in AWSV.
If a user changes a value, the user always gets a "copy" to the char settings and optionally effects account wide settings. Which values are effectively shown/used depends on the mode. |
|
01/26/16, 06:30 AM | #18 |
|
you mean like
Lua Code:
Last edited by Terrillyn : 01/26/16 at 06:38 AM. |
01/26/16, 06:41 AM | #19 | |
If the user is in account wide mode, the account wide values are used and changed. If the user switches to char mode, all settings changed while in account wide mode are still the same. /edit: The only "problem" is: 1. User A made a change while in AW mode 2. User B made a change while in AW mode 3. User A switches to Char mode: the value would change back to User A last change. Is that what you want, or should User A get a fresh copy of the AW settings? In this case you have to do, what I posted before. Last edited by votan : 01/26/16 at 06:52 AM. |
||
01/26/16, 09:12 AM | #20 | |
|
ZO_DeepTableCopy has an optional second argument, the destination table. If you don't provide it, a new table is created. |
|
ESOUI » Developer Discussions » Lua/XML Help » Having issues creating an account-wide settings toggle |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|