Thread Tools Display Modes
Prev Previous Post   Next Post Next
08/09/18, 06:49 PM   #1
Dekthro
Join Date: Oct 2016
Posts: 2
Circonians stambar tutorial, UI error

I've made it to part 3 of Circonians Stamina Bar tutorial and I am receiving the error

user:/AddOns/Dek01/Dek01.lua:39: attempt to index a nil value
stack traceback:
user:/AddOns/Dek01/Dek01.lua:39: in function 'Dek01:Initialize'
user:/AddOns/Dek01/Dek01.lua:29: in function 'Dek01.OnAddOnLoaded'
I've combed through my lua file trying to resolve this on my own but I am just not seeing what it could be.

Lua Code:
  1. -------------------------------------------------------------------------------------------------
  2. --  Libraries --
  3. -------------------------------------------------------------------------------------------------
  4. local LAM2 = LibStub:GetLibrary("LibAddonMenu-2.0")
  5.  
  6. Dek01 = {}
  7. Dek01.Default = {
  8.     OffsetX = 20,
  9.     OffsetY = 75,
  10.     Show = true,
  11.     StaminaBarColor = {1, 0, 0, 1},
  12.     BarWidth = 300,
  13.     BarHeight = 50,
  14. }
  15.  
  16. -------------------------------------------------------------------------------------------------
  17. --  Initialize Variables --
  18. -------------------------------------------------------------------------------------------------
  19. Dek01.name = "Dek01"
  20. Dek01.version = 1
  21. Dek01.varVersion = 2
  22.  
  23. -------------------------------------------------------------------------------------------------
  24. --  OnAddOnLoaded  --
  25. -------------------------------------------------------------------------------------------------
  26. function Dek01.OnAddOnLoaded(event, addonName)
  27.    if addonName ~= Dek01.name then return end
  28.  
  29.     Dek01:Initialize()
  30. end
  31.  
  32. -------------------------------------------------------------------------------------------------
  33. --  Initialize Function --
  34. -------------------------------------------------------------------------------------------------
  35. function Dek01:Initialize()
  36.     Dek01.savedVars = ZO_SavedVars:New("Dek01Vars", Dek01.varVersion, nil, Dek01.Default)
  37.    
  38.     Dek01.CreateSettingsWindow()
  39.     Dek01StaminaBarWindow:SetHidden(not Dek01.savedVars.Show)
  40.     Dek01.SetBarSize(Dek01.savedVars.BarWidth, Dek01.savedVars.BarHeight)
  41.     Dek01StaminaBarWindowStatusBar:SetColor(unpack(Dek01.savedVars.StaminaBarColor))
  42.  
  43.     local current, max, effectiveMax = GetUnitPower("player", POWERTYPE_STAMINA)
  44.     Dek01StaminaBarWindowStatusBar:SetMinMax(0, max)                    -- Set max stamina
  45.     Dek01StaminaBarWindowStatusBar:SetValue(current)                    -- Set current stamina
  46.  
  47.     local ourName = GetUnitName("player")                               --Get player name
  48.     Dek01StaminaBarWindowLabel:SetText(ourName)                         --Set label to player name
  49.  
  50.     Dek01StaminaBarWindow.ClearAnchors()
  51.     Dek01StaminaBarWindow:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, Dek01.savedVars.OffsetX, Dek01.savedVars.OffsetY)
  52.    
  53.     EVENT_MANAGER:UnregisterForEvent(Dek01.name, EVENT_ADD_ON_LOADED)   --Unregister event
  54. end
  55.  
  56. -------------------------------------------------------------------------------------------------
  57. --  Other Functions --
  58. -------------------------------------------------------------------------------------------------
  59.  function Dek01.UpdateStamina(eventCode, unitTag, powerIndex, powerType, powerValue, powerMax, powerEffectiveMax)
  60.  
  61.     if powerType == POWERTYPE_STAMINA then
  62.         Dek01StaminaBarWindowStatusBar:SetMinMax(0, powerMax)                   -- Set max stamina
  63.         Dek01StaminaBarWindowStatusBar:SetValue(powerValue)                 -- Set current stamina
  64.     end
  65. end
  66.  
  67. function Dek01.SaveLoc()
  68.     Dek01.savedVars.OffsetX = Dek01StaminaBarWindow:GetLeft()
  69.     Dek01.savedVars.OffsetY = Dek01StaminaBarWindow:GetTop()
  70. end
  71.  
  72. -------------------------------------------------------------------------------------------------
  73. --  Restore Functions --
  74. -------------------------------------------------------------------------------------------------
  75.  function Dek01.SetBarSize(_width, _height)
  76.     Dek01StaminaBarWindowStatusBar:SetDimensions(_width, _height)
  77.     Dek01StaminaBarWindowBackdrop:SetDimensions(_width, _height)
  78.     Dek01StaminaBarBorder:SetDimensions(_width, _height)
  79.     Dek01StaminaBarWindow:SetDimensions(_width, _height)
  80. end
  81.  
  82. -------------------------------------------------------------------------------------------------
  83. --  Menu Functions --
  84. -------------------------------------------------------------------------------------------------
  85. function Dek01.CreateSettingsWindow()
  86.     local panelData = {
  87.         type = "panel",
  88.         name = "Dek01",
  89.         displayName = "DekUI",
  90.         author = "Dekthro",
  91.         version = Dek01.version,
  92.         slashCommand = "/dekui",
  93.         registerForRefresh = true,
  94.         registerForDefaults = true,
  95.     }
  96.  
  97.     local cntrlOptionsPanel = LAM2:RegisterAddonPanel("Dek_01", panelData)
  98.    
  99.     local optionsData = {
  100.         [1] = {
  101.             type = "header",
  102.             name = "Stamina Bar Settings",
  103.         },
  104.         [2] = {
  105.             type = "description",
  106.             text = "Here you can adjust how the stamina bar works.",
  107.         },
  108.         [3] = {
  109.             type = "checkbox",
  110.             name = "Show Stamina Bar",
  111.             tooltip = "When ON the stamina bar will be visible. When OFF the stamina bar will be hidden.",
  112.             default = true,
  113.             getFunc = function() return Dek01.savedVars.Show end,
  114.             setFunc = function(newValue)
  115.                 Dek01.savedVars.Show = newValue
  116.                 Dek01StaminaBarWindow:SetHidden(not newValue) end,
  117.         },
  118.         [4] = {
  119.             type = "slider",
  120.             name = "Select Width",
  121.             tooltip = "Adjusts the width of the stamina bar.",
  122.             min = 100,
  123.             max = 1000,
  124.             step = 1,
  125.             default = 300,
  126.             getFunc = function() return Dek01.savedVars.BarWidth end,
  127.             setFunc = function(newValue)
  128.                 Dek01.savedVars.BarWidth = newValue
  129.                 Dek01.SetBarSize(newValue, Dek01.savedVars.BarHeight)
  130.                 end,
  131.         },
  132.         [5] = {
  133.             type = "slider",
  134.             name = "Select Height",
  135.             tooltip = "Adjusts the height of the stamina bar.",
  136.             min = 25,
  137.             max = 100,
  138.             step = 1,
  139.             default = 50,
  140.             getFunc = function() return Dek01.savedVars.BarHeight end,
  141.             setFunc = function(newValue)
  142.                 Dek01.savedVars.BarHeight = newValue
  143.                 Dek01.SetBarSize(Dek01.savedVars.BarWidth, newValue)
  144.                 end,
  145.         },
  146.         [6] = {
  147.             type = "submenu",
  148.             name = "Colors",
  149.             tooltip = "Allows you to change colors.",
  150.             controls = {
  151.                 [1] = {
  152.                     type = "colorpicker",
  153.                     name = "Bar Color",
  154.                     tooltip = "Changes the color of the stamina bar background.",
  155.                     getFunc = function() return unpack(Dek01.savedVars.StaminaBarColor ) end,
  156.                     setFunc = function(r,g,b,a)
  157.                         local alpha = Dek01StaminaBarWindowStatusBar:GetAlpha()
  158.                         Dek01.savedVars.StaminaBarColor = { r, g, b, a}
  159.                         Dek01StaminaBarWindowStatusBar:SetColor( r, g, b, a)
  160.                         end,
  161.                 },
  162.             }
  163.         }
  164.     }
  165.    
  166.     LAM2:RegisterOptionControls("Dek_01", optionsData)
  167. end
  168.  
  169. -------------------------------------------------------------------------------------------------
  170. --  Register Events --
  171. -------------------------------------------------------------------------------------------------
  172. EVENT_MANAGER:RegisterForEvent(Dek01.name, EVENT_ADD_ON_LOADED, Dek01.OnAddOnLoaded)
  173. EVENT_MANAGER:RegisterForEvent(Dek01.name, EVENT_POWER_UPDATE, Dek01.UpdateStamina)

Thank you!
  Reply With Quote
 

ESOUI » Developer Discussions » Lua/XML Help » Circonians stambar tutorial, UI error


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