Thread: Addon Etiquette
View Single Post
04/24/14, 07:35 PM   #46
Stormknight
 
Stormknight's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 128
Something I have done with my latest addon is try to segregate the naming within my global namespace for the addon.

In it's simplest forms, where I have a namespace of MyAddon I add a table named .UI for all UI elements.

This means there is no chance of having naming issues where a UI control and a function have the same name

Lua Code:
  1. MyAddon = {}
  2. MyAddon.vars = ZO_SavedVars:NewAccountWide("MyAddon_SavedVariables", 1, nil, MyAddon.defaults)
  3.  
  4. MyAddon.UI = {}    -- Table for holding UI controls.
  5. MyAddon.UI.TLW = WINDOW_MANAGER:CreateTopLevelWindow("MyAddonTopLevelFrame")
  6. MyAddon.UI.TLW:SetAnchor(CENTER)
  7. MyAddon.UI.TLW:SetDimensions(200, 50)
  8.  
  9. MyAddon.UI.WindowTitle = WINDOW_MANAGER:CreateControl("MyAddonWindowTitle", myAddonTopLevelFrame, CT_LABEL)
  10.  
  11. function MyAddon.WindowTitle(myText)
  12.   MyAddon.UI.WindowTitle:SetText(myText)
  13. end

It helps me keep things tidy and is really handy when inspecting with zgoo.

MyAddon - the global namespace declared for the addon.
MyAddon.vars - this is the saved variables.
MyAddon.UI - this is for frames/controls.
  Reply With Quote