Reputation: 111
I am receiving the following error in my wow client during addon development/
83x FrameXML\OptionsFrameTemplates.lua:157: attempt to index field
'text' (a nil value)
FrameXML\OptionsFrameTemplates.lua:157: in function <FrameXML\OptionsFrameTemplates.lua:156>
Locals:
self = ShiftDropDown_Button {
0 = <userdata>
toggle = ShiftDropDown_ButtonToggle {
}
}
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index field 'text' (a nil value)"
I am calling it in the XML file with this
<Button name="ShiftDropDown_Button" inherits="InterfaceOptionsListButtonTemplate" text="Select Target">
<Size>
<AbsDimension x="150" y="10" />
</Size>
<Anchors>
<Anchor point="TOPLEFT">
<Offset x="189" y="-115" />
</Anchor>
</Anchors>
<Scripts>
<OnLoad>
ShiftDropDown_Button_OnLoad(self)
</OnLoad>
<OnClick>
ShiftDropDownFrame:Show()
</OnClick>
</Scripts>
and the function in the Lua is here
function ShiftDropDown_Button_OnLoad(self)
self:RegisterEvent('ADDON_LOADED')
self:SetScript('OnEvent', function(self, event, ...)
if event == 'ADDON_LOADED' and ... == 'TauntMasterReborn' then
TauntMasterRebornDB = TauntMasterRebornDB or {}
for option, value in pairs(TauntM_defaults) do
if not TauntMasterRebornDB[option] then TauntMasterRebornDB[option] = value end
end
self:SetText(TauntMasterRebornDBChar.SHIFTTARGET1)
end
end)
end
Can anyone shed some light on why it is throwing this error? I have searched through lots of examples and cannot find a way to debug this or solve myself.
Upvotes: 2
Views: 2359
Reputation: 71
Your button inherits from InterfaceOptionsListButtonTemplate
which inherits initially from OptionsListButtonTemplate
.
This template has a button text:
<ButtonText name="$parentText" justifyH="LEFT" wordwrap="false"/>
Here is the code, where the error occures:
function OptionsListButton_OnEnter (self)
if (self.text:IsTruncated()) then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
GameTooltip:SetText(self:GetText(), NORMAL_FONT_COLOR[1], NORMAL_FONT_COLOR[2], NORMAL_FONT_COLOR[3], 1, true);
end
end
It tries to use the property value of the button text - in this case self
- by using self.text
. The text
parentKey isn't assigned in the xml file but in the OnLoad
function, which was overwritten by yours.
To fix your template, you have to expand your ShiftDropDown_Button_OnLoad
function:
function ShiftDropDown_Button_OnLoad(self)
self.text = _G[self:GetName() .. "Text"];
self.highlight = self:GetHighlightTexture();
self:RegisterEvent('ADDON_LOADED')
self:SetScript('OnEvent', function(self, event, ...)
if event == 'ADDON_LOADED' and ... == 'TauntMasterReborn' then
TauntMasterRebornDB = TauntMasterRebornDB or {}
for option, value in pairs(TauntM_defaults) do
if not TauntMasterRebornDB[option] then TauntMasterRebornDB[option] = value end
end
self:SetText(TauntMasterRebornDBChar.SHIFTTARGET1)
end
end)
end
Upvotes: 5