Thread Tools Display Modes
11-26-14, 02:55 AM   #21
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Go install Bugger, or at the very least, turn on the "Display Lua Errors" option under Interface Options > Help. Trying to write an addon without any way to see the errors that are occurring is like trying to put together a jigsaw puzzle in a lightless room. Sure, you can do it, eventually, but it will take a lot longer and be a lot more frustrating.

Here is one section of code that should be triggering an error message:
Code:
barQWindowCheckButton:SetScript("OnClick", 
  function()
	if barQWindow:IsShown() then
        barQWindow:Hide()
    else
        barQWindow:Show()
    end
   QWindowHide = self:IsChecked()
	barQWindowCheckButton:SetShown()	
  end
)
You're calling self:IsChecked() -- but no variable named self exists in that context. An OnClick script receives two arguments; the first is indeed typically named self, but you're not assigning those arguments to variables, so they're not accessible to your code.

Code:
barQWindowCheckButton:SetScript("OnClick", function(self, button) -- fixed!
There may be other errors as well, and you should fix them before assuming you're implementing an entire concept wrong. You may be (I just skimmed, and stopped reading after I found the above error) but it's just as likely that there's nothing wrong with your implementation, and your code is just failing on basic syntax or scoping errors.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-26-14, 11:39 AM   #22
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,308
Originally Posted by Zireko View Post
I've tried to put the code together using what you all have said so far yet it's still not saving yet.
Wild guess, but did you close the game client and restart it after modifying the ToC file? While adding files to your addon folder require a complete client restart, changes to the ToC apply when you back completely out to the login screen (where you enter your email and password) and log back in.

Edit: The error Phanx pointed out is a logic error and not a syntax error, meaning the error won't show up until the code is actually run. In this case, when the button is clicked.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 11-26-14 at 01:59 PM.
  Reply With Quote
11-26-14, 02:22 PM   #23
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
I'm still working to understand the saved variables. I don't know why I can't understand them like I can understand the other part of the code. If you know of a video that explains saved variables please feel free to share the link with me. I think if I could see a tutorial and see explained very good I might be able to understand better. As for now I'm gonna keep hunting for a video on youtube that might help. Thank you all for trying your best to explain saved variables. Don't give up on me lol I'm not stopping and I will figure this out.

Also just read your latest posts. I'm going to see about downloading bugger or turning on the lua error info like phanx suggested. LOL elder scrolls online automatically shows you what is bugging in lua I didn't know wow didn't show us. There are a lot of things I'm going to have to try again and see if they work. Thank you all again for all the help.

Last edited by Zireko : 11-26-14 at 02:28 PM.
  Reply With Quote
11-26-14, 02:42 PM   #24
Banknorris
A Chromatic Dragonspawn
 
Banknorris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 153
There is not much to understand. If AAA is declared as saved variable in the toc file, then AAA value will be automatically written to a file when you log off (the value of AAA the moment you log off). The other variables, not declared as saved variables, will have their values lost.

On the other hand when you log in (more precisely when you addon is loaded), the game copies automatically the value saved in the file to AAA in the memory.

So, how to use Saved Variables? Simple everything you want to be remembered between sections (reloads, logins) must be in a saved variable. Do you want your addon to remember the last position a user put a frame into? Then every time the user moves the frame you need to also copy the position into a variable declared as a saved variable. You also need to have a script to run on PLAYER_LOGIN (or ADDON_LOADED if your addon loads on demand) to set the position of that frame according to the position stored in the variable declared as a saved variable.

For example this very simple addon uses a saved variable per char:
http://www.wowinterface.com/download...HonorGold.html
A more sophisticated addon would just have a table as saved variable instead of an ordinary true false value but the principle is the same.

Last edited by Banknorris : 11-26-14 at 02:56 PM.
  Reply With Quote
11-26-14, 05:26 PM   #25
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
I was trying again and here is the code I have it's just the saved variable I have currently. I'm trying to put this in a table and I need the saved variable to just simply check if the checkbox has been checked and save it to the saved variable. I'm also using bugger right now so I can show you the error I'm getting and I will add the attached file of my code if you need to see the rest of the code.

This is my Save Variable Code so far

Lua Code:
  1. local Name=...;--   This will retrieve our Addon ID
  2.  
  3. --  Default configuration
  4. local Config={--    This will be our upvalue where we're going to access our configuration table
  5.     barQWindowVisible=true;
  6.     barQWindowEnabled=true;
  7. }
  8. ZBarConfig=Config;-- We'll load our default into the global pointed to by our ToC
  9.  
  10. local MyFrame=CreateFrame("Frame");
  11. MyFrame:RegisterEvent("ADDON_LOADED");
  12. MyFrame:SetScript("OnEvent",function(self,event,...)
  13.     if event=="ADDON_LOADED" and (...)==Name then-- Check if our addon is the one that loaded
  14. --      If there is any saved data, it'll overwrite whatever is in the global
  15.         Config=ZBarConfig;-- Resync upvalue to saved data (defaults will remain if no data loaded)
  16.  
  17. --      Now we can use our Config upvalue as if it were our saved variable
  18.         ZBarbarQWindow:SetShown(Config.barQWindowVisible);
  19.         ZBarbarQWindow:EnableMouse(Config.barQWindowEnabled);
  20.  
  21.         self:UnregisterEvent("ADDON_LOADED");-- We no longer need this event, unregister it
  22.     end
  23. end);

This is the Error I'm getting

Lua Code:
  1. 1x ZBar\ZBar-1.0.lua:187: attempt to index global 'ZBarbarQWindow' (a nil value)
  2. ZBar\ZBar-1.0.lua:187: in function <ZBar\ZBar.lua:181

I'm trying to use the code I was given to see If I could even get it to work but having no luck lol. I also want to keep the comment in because they are letting me know what everything is doing.

187 is line 18 in lua quote above
181 is line 12 in lua quote above
Attached Files
File Type: zip ZBar.zip (39.6 KB, 147 views)

Last edited by Zireko : 11-26-14 at 05:29 PM. Reason: Little More Info
  Reply With Quote
11-26-14, 07:11 PM   #26
Banknorris
A Chromatic Dragonspawn
 
Banknorris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 153
Well that is error is not related to saved variables. You just didn't define ZBarbarQWindow anywhere then tried to use it like it was a frame.
  Reply With Quote
11-26-14, 08:21 PM   #27
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
Well fixed the error and now it's not throwing errors. But it's not saving variables either.
  Reply With Quote
11-26-14, 09:04 PM   #28
Banknorris
A Chromatic Dragonspawn
 
Banknorris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 153
What is going on here:
1) you set Config to a value (a default value)
2) you set ZBarConfig to Config (hence the same default value)
3) addon is loaded and since it is the first time the program runs then nothing was ever stored in ZBarConfig so ZBarConfig is loaded with nil (you can't prevent this)
4) Config=ZBarConfig, now Config is also nil
3) there is nothing ever changing ZBarConfig during the session so when you logoff ZBarConfig will still be nil
Try this instead:

Lua Code:
  1. local Name=...;
  2.  
  3. local MyFrame = CreateFrame("Frame");
  4. MyFrame:RegisterEvent("ADDON_LOADED");
  5. MyFrame:SetScript("OnEvent",function(self,event,...)
  6.     if event=="ADDON_LOADED" and (...)==Name then-- Check if our addon is the one that loaded
  7.         if ZBarConfig==nil then --when this line runs ZBarConfig will already have the value stored in the disk (nil if nothing previously stored)
  8.             ZBarConfig = {
  9.                 barQWindowVisible=true;
  10.                 barQWindowEnabled=true;
  11.             }
  12.         end
  13.         Config = ZBarConfig;
  14.         ZBarbarQWindow:SetShown(Config.barQWindowVisible);
  15.         ZBarbarQWindow:EnableMouse(Config.barQWindowEnabled);
  16.  
  17.         self:UnregisterEvent("ADDON_LOADED");-- We no longer need this event, unregister it
  18.     end
  19. end);

Last edited by Banknorris : 11-26-14 at 09:10 PM.
  Reply With Quote
11-27-14, 04:25 AM   #29
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,308
What are you checking to see your variables are saved? If you're checking your options frame, I don't remember you having any code setting up the initial value of your checkbuttons or writing to any sort of variable.

The idea is this. A saved variable is just a global that is registered to be recorded to file when WoW unloads the UI. This file is basically Lua code you can open and read yourself and is imported as your addon loads. That's all it is. Nothing special.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
11-27-14, 05:12 PM   #30
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
Ok, let me try to explain a little better. When I first said this I may have not explained it correctly.

I have this little frame 1 in my zbar options window that I've created. It's a little checkbox that you can simply check to hide or un hide the frame if you want.

Now I have many other little frames like this one so I'm going to have to make a saved variable table. What I'm trying to simply save is if the checkbox has been checked or un checked for each frame. I have a total of 8 different checkboxes to do this with. As I said before I'm still very new to code so if you wish to help please let me know where each part of code should go.

Here is my little frame 1

Lua Code:
  1. barQWindowCheckButton = CreateFrame("CheckButton", "barQWindowCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  2. barQWindowCheckButton:SetPoint("TOPLEFT", 25, -65);
  3. barQWindowCheckButton_GlobalNameText:SetText("Frame 1 Hide");
  4. barQWindowCheckButton.tooltip = "This is will hide the frame.";
  5. barQWindowCheckButton:SetScript("OnClick",
  6.   function(self, button)
  7.     if barQWindow:IsShown() then
  8.         barQWindow:Hide()
  9.     else
  10.         barQWindow:Show()
  11.     end
  12.   end
  13. );
  Reply With Quote
11-27-14, 06:18 PM   #31
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Code:
barQWindowCheckButton:SetScript("OnClick", 
  function(self, button)
	local checked = self:GetChecked()
	barQWindow:SetShown(checked) then
        savedVariables["someFrame"] = checked
  end
)
For example.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
11-27-14, 09:45 PM   #32
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
Kind of understand but not fully can you elaborate more.
  Reply With Quote
11-28-14, 02:22 AM   #33
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Add this to your TOC file:

Code:
## SavedVariables: ZBarConfig
This tells WoW to save the variable named "ZBarConfig" between sessions. If you never create such a variable, the saved value will be nil. If you write "ZBarConfig = 5" in your code, the saved value will be the number 5. That's it. There's nothing magical about this. It just keeps track of a value between sessions, when normally everything in memory is simply discarded.

Add this to the top of your Lua file, outside of any functions:

Code:
ZBarConfig = {
    barQWindowVisible = true,
    barQWindowEnabled = true,
     -- other values here
}
At this point, when you're having thie much trouble with the basic concept, you should keep it as simple as possible. Don't worry about complex initialization procedures. Just write the variable and its default value in the main chunk (outside any functions) of your file. This is what happens during the loading process:
  1. WoW reads your TOC file.
  2. WoW reads each file listed in your TOC file, in the order they're listed.
    ==> At this step, the variable is created with the default value written in your Lua file.
  3. WoW reads your addon's saved variables.
    ==> At this step, if the variable was saved in a previous session, then the saved value overwrites the default value, and the variable now contains the saved value.
  4. WoW fires an ADDON_LOADED event with your addon's name as arg1.
  5. ....
  6. After the above steps have been repeated for all addons, and all other loading procedures have finished, WoW fires a PLAYER_LOGIN event.

Add this to the code you run in response to your addon's ADDON_LOADED event:

Code:
barQWindow:SetShown(ZBarConfig.barQWindowVisible)
Make sure you've already created "barQWindow" before this point.

Change your checkbox OnClick handler to this:

Code:
barQWindowCheckButton:SetScript("OnClick", function(self, button)
    ZBarConfig.barQWindowVisible = not self:GetChecked()
    barQWindow:SetShown(ZBarConfig.barQWindowVisible)
end)
The first line inverts the "checked" state -- because the saved value is "should the frame be shown" but the checkbox is labelled "should be the frame be hidden" -- and saves it into your saved variable.

The second line shows or hides the frame according to the new saved value.

Add this to your option panel's refresh function:

Code:
barQWindowCheckButton:SetChecked(not ZBarConfig.barQWindowVisible)
If you don't have a refresh function yet, you should add one -- this is a function the default UI will call each time your options panel is shown, and should be used to update the display state of each widget (checkbox, text field, dropdown, etc.) to match the current state of things in your saved variables etc.

Code:
function <options panel reference>:refresh()
    -- update widget states here
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 11-28-14 at 07:46 PM.
  Reply With Quote
11-28-14, 09:15 AM   #34
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
getting an error from this line of code

Lua Code:
  1. barQWindowCheckButton:SetScript("OnClick", function(self, button)
  2.     ZBarConfig.barQWindowVisible = not self:IsChecked()
  3.     barQWindow:SetShown(ZBarConfig.barQWindowVisible)
  4. end)

Lua Code:
  1. 4x ZBar\ZBar-1.0.lua:57: attempt to call method 'IsChecked' (a nil value)
  2. ZBar\ZBar-1.0.lua:57: in function <ZBar\ZBar.lua:51

I've done exactly as you've instructed phanx. So I'm not sure why IsChecked comming back as a nil value.
  Reply With Quote
11-28-14, 09:58 AM   #35
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,237
Replace self:IsChecked() with self:GetChecked(). There is no API "IsChecked" which why you have a nil error. http://wowpedia.org/API_CheckButton_GetChecked
  Reply With Quote
11-28-14, 10:29 AM   #36
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
I'm not sure what I'm doing wrong now. I'm going to attach my addon so you all can see it. I checked for bugs and not getting any bugs from the code now since i changed the IsChecked to GetChecked. I'll make it a little easier to see the lua by showing it here. I have ## SavedVariables: ZBarConfig in my Toc file.

Lua Code:
  1. --Want to add Show Hide function for each window. ( barQWindow, barAWindow, barMWindow, barCWindow )
  2. --With the Show Hide I want to add this in an addon options window.
  3. --Want to add a lock frame for each window.
  4. --With lock frame I want to add this in an addon options window.
  5.  
  6. --Create a button using lua that pulls up a window for ZBar Options.
  7.  
  8. --Saved Variable Table
  9. ZBarConfig = {
  10.     barQWindowVisible = true,
  11.     barQWindowEnabled = true,
  12. }
  13.  
  14. -- creates a generic button in the middle of the screen --
  15. ZBarButton = CreateFrame("Button","ZBarButton",UIParent,"UIPanelButtonTemplate")
  16. ZBarButton:SetPoint("CENTER",0,0)
  17. ZBarButton:SetWidth(30)
  18. ZBarButton:SetHeight(30)
  19. ZBarButton:SetText("ZB")
  20. ZBarButton:SetMovable(true)
  21. ZBarButton:RegisterForDrag("LeftButton")
  22. ZBarButton:SetScript("OnDragStart",ZBarButton.StartMoving)
  23. ZBarButton:SetScript("OnDragStop",ZBarButton.StopMovingOrSizing)
  24.  
  25. ZBarOptionFrame = CreateFrame("Frame")
  26. ZBarOptionFrame:ClearAllPoints()
  27. ZBarOptionFrame:SetBackdrop(StaticPopup1:GetBackdrop())
  28. ZBarOptionFrame:SetHeight(300)
  29. ZBarOptionFrame:SetWidth(300)
  30. ZBarOptionFrame:Hide(true)
  31.  
  32. ZBarOptionFrame.text = ZBarOptionFrame:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
  33. ZBarOptionFrame.text:SetPoint("CENTER", 0, 125)
  34. ZBarOptionFrame.text:SetText("ZBar Options Verison 1.0")
  35. ZBarOptionFrame:SetPoint("CENTER", 0, 0)
  36.  
  37. ZBarButton:RegisterForClicks("AnyUp")
  38. ZBarButton:SetScript("OnClick", function(self, button, ...)
  39.     if (button == "RightButton") then
  40.         if ZBarOptionFrame:IsShown() then
  41.             ZBarOptionFrame:Hide()
  42.         else
  43.             ZBarOptionFrame:Show()
  44.         end
  45.     end
  46. end)
  47.  
  48. -- My window Names are barQWindow (name frame 1), barCWindow (name frame 2), barMWindow (name frame 3), barAWindow (name frame 4)
  49.  
  50. --Frame 1 (barQWindow)
  51. barQWindowCheckButton = CreateFrame("CheckButton", "barQWindowCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  52. barQWindowCheckButton:SetPoint("TOPLEFT", 25, -65);
  53. barQWindowCheckButton_GlobalNameText:SetText("Frame 1 Hide");
  54. barQWindowCheckButton.tooltip = "This is will hide the frame.";
  55. barQWindowCheckButton:SetScript("OnClick", function(self, button)
  56.     ZBarConfig.barQWindowVisible = not self:GetChecked()
  57.     barQWindow:SetShown(ZBarConfig.barQWindowVisible)
  58. end)
  59.  
  60. --Frame 2(barCWindow)
  61. barCWindowCheckButton = CreateFrame("CheckButton", "barCWindowCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  62. barCWindowCheckButton:SetPoint("TOPLEFT", 25, -85);
  63. barCWindowCheckButton_GlobalNameText:SetText("Frame 2 Hide");
  64. barCWindowCheckButton.tooltip = "This is will hide the frame.";
  65. barCWindowCheckButton:SetScript("OnClick",
  66.   function()
  67.     if barCWindow:IsShown() then
  68.         barCWindow:Hide()
  69.     else
  70.         barCWindow:Show()
  71.     end
  72.   end
  73. );
  74.  
  75. --Frame 3 (barMWindow)
  76. barMWindowCheckButton = CreateFrame("CheckButton", "barMWindowCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  77. barMWindowCheckButton:SetPoint("TOPLEFT", 25, -105);
  78. barMWindowCheckButton_GlobalNameText:SetText("Frame 3 Hide");
  79. barMWindowCheckButton.tooltip = "This is will hide the frame.";
  80. barMWindowCheckButton:SetScript("OnClick",
  81.   function()
  82.     if barMWindow:IsShown() then
  83.         barMWindow:Hide()
  84.     else
  85.         barMWindow:Show()
  86.     end
  87.   end
  88. );
  89.  
  90. --Frame 4 (barAWindow)
  91. barAWindowCheckButton = CreateFrame("CheckButton", "barAWindowCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  92. barAWindowCheckButton:SetPoint("TOPLEFT", 25, -125);
  93. barAWindowCheckButton_GlobalNameText:SetText("Frame 4 Hide");
  94. barAWindowCheckButton.tooltip = "This is will hide the frame.";
  95. barAWindowCheckButton:SetScript("OnClick",
  96.   function()
  97.     if barAWindow:IsShown() then
  98.         barAWindow:Hide()
  99.     else
  100.         barAWindow:Show()
  101.     end
  102.   end
  103. );
  104.  
  105. --This will be to lock the frame into place
  106.  
  107. --Frame 1 (barQWindow)
  108. barQWindowLockCheckButton = CreateFrame("CheckButton", "barQWindowLockCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  109. barQWindowLockCheckButton:SetPoint("TOPLEFT", 150, -65);
  110. barQWindowLockCheckButton_GlobalNameText:SetText("Frame 1 Lock");
  111. barQWindowLockCheckButton.tooltip = "This is will lock the frame in place.";
  112. barQWindowLockCheckButton:SetScript("OnClick",
  113.   function()
  114.     if barQWindow:IsMovable() then
  115.         barQWindow:SetMovable(false)
  116.     else
  117.         barQWindow:SetMovable(true)
  118.     end
  119.   end
  120. );
  121.  
  122. --Frame 2 (barCWindow)
  123. barCWindowLockCheckButton = CreateFrame("CheckButton", "barCWindowLockCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  124. barCWindowLockCheckButton:SetPoint("TOPLEFT", 150, -85);
  125. barCWindowLockCheckButton_GlobalNameText:SetText("Frame 2 Lock");
  126. barCWindowLockCheckButton.tooltip = "This is will lock the frame in place.";
  127. barCWindowLockCheckButton:SetScript("OnClick",
  128.   function()
  129.     if barCWindow:IsMovable() then
  130.         barCWindow:SetMovable(false)
  131.     else
  132.         barCWindow:SetMovable(true)
  133.     end
  134.   end
  135. );
  136.  
  137. --Frame 3 (barMWindow)
  138. barMWindowLockCheckButton = CreateFrame("CheckButton", "barMWindowLockCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  139. barMWindowLockCheckButton:SetPoint("TOPLEFT", 150, -105);
  140. barMWindowLockCheckButton_GlobalNameText:SetText("Frame 3 Lock");
  141. barMWindowLockCheckButton.tooltip = "This is will lock the frame in place.";
  142. barMWindowLockCheckButton:SetScript("OnClick",
  143.   function()
  144.     if barMWindow:IsMovable() then
  145.         barMWindow:SetMovable(false)
  146.     else
  147.         barMWindow:SetMovable(true)
  148.     end
  149.   end
  150. );
  151.  
  152. --Frame 4 (barMWindow)
  153. barAWindowLockCheckButton = CreateFrame("CheckButton", "barAWindowLockCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  154. barAWindowLockCheckButton:SetPoint("TOPLEFT", 150, -125);
  155. barAWindowLockCheckButton_GlobalNameText:SetText("Frame 4 Lock");
  156. barAWindowLockCheckButton.tooltip = "This is will lock the frame in place.";
  157. barAWindowLockCheckButton:SetScript("OnClick",
  158.   function()
  159.     if barAWindow:IsMovable() then
  160.         barAWindow:SetMovable(false)
  161.     else
  162.         barAWindow:SetMovable(true)
  163.     end
  164.   end
  165. );
  166.  
  167. --Function to refresh the options panel
  168. function ZBarOptionFrame:refresh()
  169.     barQWindowCheckButton:SetChecked(not ZBarConfig.barQWindowVisible)
  170. end
  171.  
  172. --Addon_Loaded
  173.  
  174. local MyFrame=CreateFrame("Frame");
  175. MyFrame:RegisterEvent("ADDON_LOADED");
  176. MyFrame:SetScript("OnEvent",function(self,event,...)
  177.     if event=="ADDON_LOADED" and (...)==Name then
  178.        
  179.         barQWindow:SetShown(ZBarConfig.barQWindowVisible)
  180.        
  181.         self:UnregisterEvent("ADDON_LOADED");
  182.     end
  183. end);

I did everything phanx told me and trying to make sure I have this correct. The frame 1 is the only one I'm saving right now and it hides the frame however it doesn't save it still. If you see what I'm messing up on please let me know.
Attached Files
File Type: zip ZBar.zip (39.4 KB, 144 views)
  Reply With Quote
11-28-14, 01:08 PM   #37
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,237
I need some sleep, so someone will beat me to a more thorough look (Phanx, most likely), but here's a short list:
  • Gah! XML is not anyone's friend
  • In fact, get rid of the XML file as everything in it already exists in your Lua file
  • Your formatting is terrible. Use tabs, not spaces
  • This won't even load, as your ADDON_LOADED event has no idea what "NAME" is because it doesn't exist
  • There is no parameter to Hide() or Show() - passing true or false is for other games
  • Lua will ignore all your semicolons. Sure, Blizzard code uses them, but they are pointless and ugly
  • There are leaking globals all over the place
  Reply With Quote
11-28-14, 02:25 PM   #38
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
Kind of figured everything you just said lol. I'm working on a much smaller code now so I can try and learn saved variables. This code is just practice and that's the only reason I have the xml in there. It's for my own learning if I ever need to edit or fix anything. I doubt I will ever need the xml but it's good for me to learn it.
  Reply With Quote
11-28-14, 05:10 PM   #39
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,308
I admit my version of the saved variable code may have been more advanced than was needed to explain. Defining a saved variable in the ToC just tells WoW to record the named global when logging out and read it back in when loading your addon. In the Lua code, you just use the global as you always would. Anything you do to the global will be overwritten with the saved data (if any) when ADDON_LOADED fires for your addon. Anything you do after that event will be saved.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 11-28-14 at 05:12 PM.
  Reply With Quote
11-28-14, 07:49 PM   #40
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by myrroddin View Post
Your formatting is terrible. Use tabs, not spaces
I would generally agree with this, but using spaces is fine if you use them consistently. Just don't indent some lines by 3 spaces, then others by 4 spaces, and this random line there by 5 spaces. That's why tabs are better -- a tab is always a tab, and you don't have to worry about accidentally deleting part of a tab or configuring your editor to pretend that 4 spaces are a single tab character and hoping it never screws up.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » I Need some Help On an Addon I'm working On

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