Thread Tools Display Modes
05-10-13, 07:51 AM   #1
CrazyCactuaR
A Deviate Faerie Dragon
Join Date: Oct 2011
Posts: 13
Unhappy Stuck trying to load a table of varibles

This must be a common cry for help I'm sorry but i really cannot get my head round it really. I've been spending alot of time browsing through google and wowinterface but any examples i seem to find i'm having trouble understanding how to actually load up the settings that i've saved.

So my TOC file saves MyAddonSettings which is a table

My table is laid out as following
Code:
MyAddonSettings = {
Var1 = true
Var2 = false
Var3 = false
Var4 = false
}
I've setup the addon's OnEvent to trigger for "ADDON_LOADED" which i presume is when my table var will be ready to be read.

This is where i'm stuck, I honestly cannot figure out how to load the settings onto the addon.

Any help regarding this would help me out and thank you in advance.
  Reply With Quote
05-10-13, 08:16 AM   #2
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Code:
## Interface: 50200
## SavedVariables: MyAddonSettings
Code:
local addonName = ...

MyAddonSettings = { -- this acts like default settings for the table
  Var1 = true,
  Var2 = false,
  Var3 = false,
  Var4 = false,
}

local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", function(f, event, name)
  if event == "ADDON_LOADED" and name == addonName then
    print(MyAddonSettings, MyAddonSettings.Var1) -- once this happens, if "MyAddonSettings" has loaded something that was saved, it automatically repalces the values that MyAddonSettings returns, otherwise the default table mentioned on the top of the file is what this table will contain
  end
end)
__________________
Profile: Curse | Wowhead
  Reply With Quote
05-10-13, 08:16 AM   #3
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
By the time ADDON_LOADED fires the variable has already been overwritten by the one from SavedVariables, the event is essentially just notifying you that "MyAddonSettings" now contains the loaded values.
  Reply With Quote
05-10-13, 08:21 AM   #4
CrazyCactuaR
A Deviate Faerie Dragon
Join Date: Oct 2011
Posts: 13
Originally Posted by Vlad View Post
Code:
## Interface: 50200
## SavedVariables: MyAddonSettings
Code:
local addonName = ...

MyAddonSettings = { -- this acts like default settings for the table
  Var1 = true,
  Var2 = false,
  Var3 = false,
  Var4 = false,
}

local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", function(f, event, name)
  if event == "ADDON_LOADED" and name == addonName then
    print(MyAddonSettings, MyAddonSettings.Var1) -- once this happens, if "MyAddonSettings" has loaded something that was saved, it automatically repalces the values that MyAddonSettings returns, otherwise the default table mentioned on the top of the file is what this table will contain
  end
end)
Thank you very much
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Stuck trying to load a table of varibles


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off