04/24/14, 08:36 PM | #1 |
Help with ZO_SavedVars Syntax
I need to add a single one line value to the HarvestMap.lua that I read first thing when the mod loads. I need to get a boolean value right away first thing.
Lua Code:
Lua Code:
So what I was looking for was how to have it be something like this: Lua Code:
What is the proper syntax? Last edited by Sharlikran : 04/24/14 at 08:45 PM. |
|
04/24/14, 08:51 PM | #2 |
Aren't you storing the results of Harvest.setting.account in your saved variables?
Are you waiting for EVENT_ADD_ON_LOADED before you actually try to grab stuff from your saved variables? |
|
04/24/14, 08:55 PM | #3 |
I've seen several other add-on authors sorely over complicate the SavedVars process, so hopefully I can help.
Basically, what i do in my add-ons is define a master table for all the data that a) I need default values for and b) want to save after reload. Then in my init function I setup the table: Code:
A.saved = { ["addon_visible"] = true, ["addon_orientation"] = 'v', ["open_menu_alpha"] = 0.25, ["super_important_data"] = {}, } Code:
A.saved = ZO_SavedVars:NewAccountWide( "Addon_SavedVariables", A.version, "saved", A.saved ) Sure, granted, there are reasons to keep separate SavedVariables.. but most of our projects don't really meet the criteria for needing to. Hope this helps! P.S. LAM syntax looks correct on first glance to me! |
|
04/24/14, 09:16 PM | #4 | |
Lua Code:
Lua Code:
So I am trying to test add this feature while I have an existing HarvestMap.lua file in Saved Variables. So naturally the file exists but the value is not saved in it yet. The entire block:
Warning: Spoiler
Lua Code:
I don't have an ulterior motive. I'm not expecting you to like download the file and troubleshoot my entire code. However, I'll link it but I don't know how to put it so you know I'm not trying to ask for more then is allowed. Just you want to know something that I may not be doing feel free. That can't sound right but I am trying to be respectful. What i don't get is when the EVENT_ADD_ON_LOADED fires to run OnLoad, if the value is not there I can't check for nil. If I do it will cause an exception. Because I tried this: Lua Code:
So what I am worried about is if someone uses HarvestMap 2.3.1, and they upgrade to the new version when I am done, they won't have the setting in the file. When it does not exist how can I define it? So that maybe I can say "Harvest.settings.account = {{{{{ Some Syntax Here }}}". Because I could store the value in two places if that will make it work. I don't know where to specify the default value either. Lua Code:
Last edited by Sharlikran : 04/24/14 at 09:19 PM. |
||
04/24/14, 09:24 PM | #5 |
You kind of ninja'd me before I posted. Does any of that help narrow down, maybe, the fact that I'm not defining the default value, or something.
EDIT: This did not work Lua Code:
Last edited by Sharlikran : 04/24/14 at 09:33 PM. |
|
04/24/14, 09:28 PM | #6 | |
|
||
04/24/14, 10:05 PM | #7 |
I don't know how to do that, but I am trying...
Lua Code:
Then I tried this Lua Code:
Then I tried and this Lua Code:
This is what it looks like in game. HarvestMap is gone EDIT: LOL! If I specify "addOnName" I can't use "addon" Last edited by Sharlikran : 04/24/14 at 10:20 PM. |
|
04/24/14, 10:18 PM | #8 |
Lua Code:
So is it EVENT_MANAGER:RegisterForEvent("HarvestMap", EVENT_ADD_ON_LOADED, function (eventCode, addOnName) OR EVENT_MANAGER:RegisterForEvent("HarvestMap", EVENT_ADD_ON_LOADED, function Harvest.OnLoad(eventCode, addOnName) OR EVENT_MANAGER:RegisterForEvent("HarvestMap", EVENT_ADD_ON_LOADED, function OnLoad(eventCode, addOnName) Some of those gave me errors about an "(" expected near "Harvest... Last edited by Sharlikran : 04/24/14 at 10:21 PM. |
|
04/24/14, 10:52 PM | #9 |
The first one should work:
Code:
EVENT_MANAGER:RegisterForEvent("HarvestMap", EVENT_ADD_ON_LOADED, function (eventCode,addOnName) if addOnName == "HarvestMap" then Initialize() Harvest.OnLoad(eventCode, addOnName) end end) Looking good tho! Last edited by archpoet : 04/24/14 at 10:52 PM. Reason: code blocks |
|
04/25/14, 03:52 AM | #10 | |
|
Anonymous functions will just make your debugging life harder, because if you have an error in that part of the code, the backtrace won't tell you where it happened. |
|
04/25/14, 02:21 PM | #11 |
Anonymous functions are fine. If you're just doing a little bit in the function and you only need it that one time, why not? Besides, the error's backtrace will give you a line number and say the error was "in anonymous function".
|
|
05/01/14, 02:18 AM | #12 |
Still having issues creating a new section now. I want a list of item ID numbers, indexed by the itemID.
I declared my save variable table or whatever it's called Lua Code:
This is what I wrote to insert into that table Lua Code:
Here is what I expect it to look like: Lua Code:
This is what it looks like so far
Warning: Spoiler
Lua Code:
Here is the routine to check for duplicate itemID numbers. Lua Code:
This is the error I am getting. How can I change the syntax to make it work? As you can see in the screen shot I do have the itemID, Item Name, and node name so I can pass those as arguments. |
|
05/01/14, 03:42 AM | #13 |
|
Have you tried using table.pack()? Just to be sure.
|
05/01/14, 08:07 AM | #14 |
Lua Code:
Lua Code:
|
|
05/01/14, 09:01 AM | #15 |
Lua Code:
Lua Code:
|
|
05/01/14, 10:53 AM | #16 | |
|
Harvest["items"]["data"][27058][1][2] will be "Red Wheat" |
|
05/01/14, 11:39 AM | #17 |
You guys may or may not be aware of this so I'm sharing it here, because it seems appropriate:
The ZO_SavedVariables inserts and retrieves saved data from inside of an @Accountname sub table. If your user is on the Overflow server, or if your user is experiencing issues with the game client, or if they disable Guild & Friend features for maintenance or a hotfix (which they have done nearly once per week since launch)... your user will fail to load their saved variables as the active account the game client will be loading them under will be the value: "" For this reason, and to support a feature I'm planning to add to my addons, I have CHANGED GEARS and am using my OWN character-name tabling of saved variable data without using ZO_SavedVariables. ## SavedVariables: mySaves ^^ that kind of line in your .txt file. Then I basically just do the following on startup: local defaults = { var1 = "", var2 = true, var3 = 3, } local charName = GetUnitName( "player" ) if not mySaves then mySaves = {} end if not mySaves[ savedVariableVersionNumber] then mySaves[ savedVariableVersionNumber] = {} end if not mySaves[ savedVariableVersionNumber][ "global" ] then mySaves[ savedVariableVersionNumber][ "global" ] = defaults end if not mySaves[ savedVariableVersionNumber][ charName ] then mySaves[ savedVariableVersionNumber][ charName ] = defaults end myAddonGlobal.Settings = mySaves[ savedVariableVersionNumber][ charName ] myAddonGlobal.GlobalSettings = mySaves[ savedVariableVersionNumber][ "global" ] That's it. LOOKS more complex than it is. It's fairly simple, really. Still partitions saved variables by version and toon but doesn't include the account name (which is pointless at this point anyway) or any profile name (which you could easily add if you wished). To read settings out I have a GetOrDefault method like: myAddonGlobal.GetOrDefault = function( default, varToCheck ) if varToCheck == nil then return default else return varToCheck end end And then I consume that like this: control:SetWidth( myAddonGlobal.GetOrDefault( 250, myAddonGlobal.Settings[ "control width" ] ) ) And if you change the value of myAddonGlobal.Settings[ "control width" ] it does indeed save down to the SavedVariables file just as you should expect... automatically. Basically this cleans up saved variable usage while at the same time CODING AROUND a relatively hurtful (to the user experience) game bug. EDIT: This is the process I am shifting to with my suite-wide rewrite & overhaul. You won't find examples in my currently published addons, as of 5/1/2014. My overhaul is about halfway done and after that these kind of changes will be "live" and you'll be able to see them in action.
__________________
Wykkyd Gaming • Mostly Harmless As seen on: PC Gamer • Massively • Exploring ESO • Ten Ton Hammer • Featured by Zenimax |
|
05/01/14, 01:13 PM | #18 |
Hmm interesting Wykkyd. May have to consider something similar if this sort of thing causes a headache with gatherer. But urgh .. another data fix routine I was hoping to avoid.
|
|
ESOUI » Developer Discussions » Lua/XML Help » Help with ZO_SavedVars Syntax |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|