View Single Post
04/24/14, 08:36 PM   #1
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 665
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:
  1. Harvest.nodes = ZO_SavedVars:NewAccountWide("Harvest_SavedVars", 2, "nodes", { data = {} } )
  2.     if Harvest.settings.account then
  3.         Harvest.settings = ZO_SavedVars:NewAccountWide("Harvest_SavedVars", 1, "settings",
  4.         {{{{ A bunch of stuf here }}}}
  5.     }
  6.     else
  7.         Harvest.settings = ZO_SavedVars:New("Harvest_SavedVars", 1, "settings",
  8.         {{{{ A bunch of stuf here }}}}
  9.     }
  10.     end
That is what loads so I get an exception because Lua does not know what the value of Harvest.settings.account is. Harvest settings account is defined with LAM.
Lua Code:
  1. LAM:AddHeader(panelID, "HarvestSettingsHeader", "Account Wide Settings")
  2.  
  3.     LAM:AddCheckbox(panelID, "HarvestMapSettings", "Account Wide Settings", "Enable account Wide Settings",
  4.         function()
  5.             return Harvest.settings.account
  6.         end,
  7.         function( value )
  8.             Harvest.settings.account = value
  9.             ReloadUI()
  10.         end,
  11.     false, nil)
Side question: did I define that correctly with LAM so that the UI Will reload ONLY when a player changes the value?

So what I was looking for was how to have it be something like this:
Lua Code:
  1. ???? Harvest.settings.account = ZO_SavedVars:NewAccountWide("Harvest_SavedVars", 1, "accountWideBool", accountWideBool )  {{----The line I want to add ----}}
  2. Harvest.nodes = ZO_SavedVars:NewAccountWide("Harvest_SavedVars", 2, "nodes", { data = {} } )
  3.     if Harvest.settings.account then
  4.         Harvest.settings = ZO_SavedVars:NewAccountWide("Harvest_SavedVars", 1, "settings",
  5.         {{{{ A bunch of stuf here }}}}
  6.     }
  7.     else
  8.         Harvest.settings = ZO_SavedVars:New("Harvest_SavedVars", 1, "settings",
  9.         {{{{ A bunch of stuf here }}}}
  10.     }
  11.     end
If I don't put any lines that will cause an exception, with LAM the boolean setting will be written to the settings file as "["account"] = false," so I know it will be there at some point. However, I want to get that value, but, if it's not there I want the default to be false. Naturally I can change the AddCheckbox routine in lam to have a different value, like Harvest.accountWidePrefs. I just don't know what to change it to so that it gets the setting right away and doesn't cause an exception.

What is the proper syntax?

Last edited by Sharlikran : 04/24/14 at 08:45 PM.
  Reply With Quote