Thread Tools Display Modes
11-04-12, 11:09 AM   #1
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Lua error that I'm not sure how to fix. Need help!

Hi, I have a script that is causing a Lua error message and I do not understand why it is wrong.

I have a button that should only show if a KgPanel frame is visible so I put this OnLoad script into it:

Code:
if kgPanels:FetchFrame("chatBox2"):IsVisible() then
self:Hide()
else
self:Show()
end
and the "chatBox2" frame has an OnLoad script "self:Hide() so the button should not show. However I get this error message when I log in or reload:

Code:
Message: [string "chatBox2ButtonExpand_OnLoad"]:4: attempt to index a nil value
Does anyone know what I'm doing wrong with this?
  Reply With Quote
11-04-12, 12:34 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Please post full error and code. From here, all I can say is either kgPanels, self, or the return from kgPanels:FetchFrame("chatBox2") is nil. Without all the info, there's no way to tell from here.

Note, full error posting will help us with stack trace info to see if it may be propagating from another function and locals info will display the current status of any locals in the current function. Full code posting is needed in case any of the locals may be corrupted through some error before the section you had supplied.
__________________
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-04-12 at 12:38 PM.
  Reply With Quote
11-05-12, 12:37 PM   #3
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by SDPhantom View Post
Please post full error and code. From here, all I can say is either kgPanels, self, or the return from kgPanels:FetchFrame("chatBox2") is nil. Without all the info, there's no way to tell from here.

Note, full error posting will help us with stack trace info to see if it may be propagating from another function and locals info will display the current status of any locals in the current function. Full code posting is needed in case any of the locals may be corrupted through some error before the section you had supplied.
Sorry about that, here it is:
Code:
Message: [string "chatBox2ButtonExpand_OnLoad"]:4: attempt to index a nil value
Time: 11/05/12 18:35:44
Count: 1
Stack: [string "chatBox2ButtonExpand_OnLoad"]:4: in function `y'
Interface\AddOns\kgPanels\kgPanels.lua:1120: in function `SetupScript'
Interface\AddOns\kgPanels\kgPanels.lua:812: in function `InitScripts'
Interface\AddOns\kgPanels\kgPanels.lua:798: in function `PlaceFrame'
Interface\AddOns\kgPanels\kgPanels.lua:705: in function `ApplyLayout'
Interface\AddOns\kgPanels\kgPanels.lua:504: in function <Interface\AddOns\kgPanels\kgPanels.lua:500>
(tail call): ?
[C]: ?
[string "safecall Dispatcher[1]"]:9: in function <[string "safecall Dispatcher[1]"]:5>
(tail call): ?
...ace\AddOns\Masque\Libs\AceAddon-3.0\AceAddon-3.0.lua:543: in function `EnableAddon'
...ace\AddOns\Masque\Libs\AceAddon-3.0\AceAddon-3.0.lua:636: in function <...ace\AddOns\Masque\Libs\AceAddon-3.0\AceAddon-3.0.lua:621>
[C]: in function `LoadAddOn'
Interface\FrameXML\UIParent.lua:299: in function `UIParentLoadAddOn'
Interface\FrameXML\UIParent.lua:322: in function `CombatLog_LoadUI'
Interface\FrameXML\UIParent.lua:692: in function <Interface\FrameXML\UIParent.lua:657>

Locals: <none>
  Reply With Quote
11-05-12, 02:00 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
I'm noticing you're loading from CombatLog_LoadUI(). Are you trying to access ChatFrame2? The code seems to be trying to access chatBox2. This is still only a guess. I don't use kgPanels and for those that are more capable, full code would help in trying to debug this problem.
__________________
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-05-12, 02:11 PM   #5
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Sorry for the confusion but the chatBox2 is actually the KgPanel. I'm not trying to access the chat box but to access the panel which I use for the background of the chat frame.

EDIT: This is the full code:

I have one button (chatBox2ButtonExpand) to show the chatBox2 frame:

OnLoad:
Code:
if kgPanels:FetchFrame("chatBox2"):IsVisible() then
self:Hide()
else
self:Show()
end
OnUpdate:
Code:
if InCombatLockdown() then return end
if kgPanels:FetchFrame("chatBox2ButtonRetract"):IsVisible() then
self:Hide()
elseif IsAltKeyDown() and not IsControlKeyDown() and not IsShiftKeyDown() then
self:Show()
else
self:Hide()
end
OnClick:
Code:
local scripts = kgPanelsDB.global.layouts["MayronUI"]["chatBox2"].scripts
if pressed then
if InCombatLockdown() then return end
kgPanels:FetchFrame("chatBox2"):Show()
if scripts.LOAD:sub(-11,-7) == "self:" then
    if scripts.LOAD:sub(-6) == "Hide()" then
        scripts.LOAD = scripts.LOAD:sub(1,-12).."self:Show()"
    end
else
    scripts.LOAD = scripts.LOAD.."\nself:Show()"
end
kgPanels:FetchFrame("chatBox2ButtonRetract"):Show()
self:Hide()
end
the ChatBox2:
OnLoad:
Code:
self:Hide()
and the ChatBox2ButtonRetract (button to hide the chatBox2 frame):
OnLoad:
Code:
if kgPanels:FetchFrame("chatBox2"):IsVisible() then
self:Show()
else
self:Hide()
end
OnUpdate:
Code:
if InCombatLockdown() then return end
if kgPanels:FetchFrame("chatBox2"):IsVisible() then
if IsAltKeyDown() and not IsControlKeyDown() and not IsShiftKeyDown() then
self:Show()
else
self:Hide()
end
else
self:Hide()
end
OnClick:
Code:
local scripts = kgPanelsDB.global.layouts["MayronUI"]["chatBox2"].scripts
if pressed then
if InCombatLockdown() then return end
kgPanels:FetchFrame("chatBox2"):Hide()
if scripts.LOAD:sub(-11,-7) == "self:" then
    if scripts.LOAD:sub(-6) == "Show()" then
        scripts.LOAD = scripts.LOAD:sub(1,-12).."self:Hide()"
    end
else
    scripts.LOAD = scripts.LOAD.."\nself:Hide()"
end
kgPanels:FetchFrame("chatBox2ButtonExpand"):Show()
self:Hide()
end
_

Last edited by Mayron : 11-05-12 at 02:37 PM.
  Reply With Quote
11-05-12, 05:34 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Based on the code and the error, my best guess would be that kgPanels is not passing "self" to your panel's OnLoad script, but it should be doing that, so I really have no idea.
__________________
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-05-12, 05:53 PM   #7
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Assuming kgPanels is doing what it "should", I'd say it's not finding chatBox2. I'll have to tear apart the addon to trace where the error might be coming from. It may just be a configuration error, which is something that wouldn't show up in code or the stack trace. For all I can tell, it could come down to something as simple as incorrect case in the spelling of chatBox2.

My first step would be to run print(self) somewhere at the top of the script, which should return a table value. Other variables to check using this would be kgPanels and kgPanels:FetchFrame("chatBox2"). Both should be table values as well.

Notice we're not checking if FetchFrame() exists in kgPanels, this is because the error is describing indexing nil, not calling it.

PS: I think I looked at kgPanels' code before and noticed they add some lines to the beginning of some if not all scripts, so I wouldn't trust the line number to be accurate.
__________________
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-05-12 at 06:05 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Lua error that I'm not sure how to fix. Need help!


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