Quantcast
Add-On Coding Help? Saved Variables - WoWInterface
Thread Tools Display Modes
07-07-12, 06:48 PM   #1
TheRealArkayn
A Deviate Faerie Dragon
 
TheRealArkayn's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 15
Add-On Coding Help? Saved Variables

Can someone with more coding experience than me please have a look at what I've done so far? I'm trying to use something like this:

Code:
-- If the variable isn't saved from last session...
if not (CM_db) then
     -- ...create the table
     CM_db = {}
end
print(type(CM_db)
...and the print() message I'm using to debug the program prints "nil" rather than "table."

I've attached a link for my add-on and I'm hoping someone can tell me why my debug message isn't printing "table." I need the table to save variables between sessions but I'm obviously doing something wrong. Please help. =)

https://dl.dropbox.com/u/1118648/CurrencyMonitor.zip

Here is the PasteBin: http://pastebin.com/RZq6YkY2
  Reply With Quote
07-07-12, 07:57 PM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,306
Without having ran it I think I can see a couple problems.
  1. You never define your event handler (in .xml since that's how you chose to create your frames) so it's doubtful your CurrencyMonitor_OnEvent function ever runs.
    You'd need a CurrencyMonitor:SetScript("OnEvent", CurrencyMonitor_OnEvent) in lua or an <OnEvent>CurrencyMonitor_OnEvent(self,event,...)</OnEvent> alongside the other script handlers in .xml.
  2. You never register for PLAYER_ENTERING_WORLD.
  3. Code:
    if (event == "ADDON_LOADED" or event == "PLAYER_ENTERING_WORLD") and arg1 == "CurrencyMonitor" then
    doesn't do what you think it does.
    You probably meant
    Code:
    if (event == "ADDON_LOADED" and arg1 == "CurrencyMonitor") or event == "PLAYER_ENTERING_WORLD" then
  Reply With Quote
07-07-12, 08:00 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,859
When are you calling CurrencyMonitor_OnEvent? And I see you are registering your events with CurrencyMonitor_OnLoad, but I don't see where you are calling this either. Do you have an XML file?

Usually, the first passed arg for SetScript is the frame itself that is calling it. THEN you'd have the event, other args, etc.

You don't need to call the function with both ADDON_LOADED and PLAYER_ENTERING_WORLD, but you don't even register PEW, so, I guess it doesn't matter.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-07-12, 09:14 PM   #4
TheRealArkayn
A Deviate Faerie Dragon
 
TheRealArkayn's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 15
-derp-

Not sure how I lost my OnEvent function call from my XML file, but I sure did. Here is the new PasteBin: http://pastebin.com/bmUVhWE9

My current issues are that my add-on is supposed to load into the edit boxes a) the default values or b) the saved values from CM_db. When I use /cm to display the GUI, it opens without values in the edit boxes and I simply can't get the GUI to open with values already there. Also, when I add values to the boxes and click "accept," the add-on should store the values in CM_db but the only thing showing in CM_db in the saved variables folder is CM_db = nil. Have I populated my tables correctly (lines 125-140 and/or lines 192-195)?



This is what I get when I populate the fields and click "accept:"

Message: Interface\AddOns\CurrencyMonitor\Frame.lua:127: attempt to index global 'CM_db' (a nil value)
Count: 1
Stack: Interface\AddOns\CurrencyMonitor\Frame.lua:127: in function `CM_UpdateAll'
[string "*:OnClick"]:1: in function <[string "*:OnClick"]:1>

Locals: v = CM_ValorEdit {
0 = <userdata>
}
j = CM_JusticeEdit {
0 = <userdata>
}
c = CM_ConquestEdit {
0 = <userdata>
}
h = CM_HonorEdit {
0 = <userdata>
}
(*temporary) = nil
(*temporary) = <table> {
threshold = "1"
tracked = true
}
(*temporary) = true
(*temporary) = "3"
(*temporary) = "4"
(*temporary) = CM_HonorEdit {
0 = <userdata>
}
(*temporary) = "4"
(*temporary) = nil
(*temporary) = "attempt to index global 'CM_db' (a nil value)"
currencyThresholds = <table> {
1 = "1"
2 = "2"
3 = "3"
4 = "4"
}
trackingTable = <table> {
1 = true
}

Last edited by TheRealArkayn : 07-07-12 at 09:16 PM. Reason: Forgot PasteBin
  Reply With Quote
07-07-12, 09:53 PM   #5
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,306
If you haven't changed your .xml CurrencyMonitor_OnLoad() never runs either.
You need to call it (or just move the contents of the function) in
Code:
<OnLoad>self:RegisterForDrag("LeftButton");</OnLoad>
So your events never register, hence your variables table never gets initialized.

Something like this
Code:
<OnLoad>self:RegisterForDrag("LeftButton");self:RegisterEvent("ADDON_LOADED");self:RegisterEvent("CHAT_MSG_CURRENCY")</OnLoad>
  Reply With Quote
07-07-12, 10:25 PM   #6
TheRealArkayn
A Deviate Faerie Dragon
 
TheRealArkayn's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 15
Bingo! I registered the events in the XML and suddenly CM_db is a table and the GUI is auto-populated. The table is saved across sessions too!

I'd say problem solved. Thanks so much to the both of you.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Add-On Coding Help? Saved Variables

Thread Tools
Display Modes

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