Thread Tools Display Modes
08-27-09, 09:05 AM   #1
rossman
A Cyclonian
 
rossman's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 39
help getting info panel plugin to work

I am trying to learn how to do some very basic lua coding. I successfully got one plugin to work(Anymeter= I am still testing it but it seems to work good).

I copied and modified a layout.lua file for my LDB display. It shows my info blocks and does not have any errors. If I create a frame like this.

local cp = CreateFrame("Frame","cp_frame")
cp:SetFrameStrata("BACKGROUND")
cp:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 0, 0)
cp:SetWidth(900)
cp:SetHeight(15)
cp:SetScale(1.2)
cp:SetBackdropColor(0, 0, 0)
cp:SetClampedToScreen(true)
cp:EnableMouse(true)
cp:Show()

Now the problem. When I modify my nUI InfoPanel Plugin.lua code to try and re parent the frame to the info panel it gives an error. Attempt to index global cp_frame (a nil value). Both lua files run fron the same folder\TOC

layout.lua
plugin.lua

My plugin.lua relevent sections

plugin.setEnabled = function( enabled )

if plugin.enabled ~= enabled then

plugin.enabled = enabled;

cp_frame:ClearAllPoints ();
cp_frame:SetPoint ("TOPLEFT", plugin.container, "TOPLEFT", 0, 0);

end
end

-------------------------------------------------------------------------------

plugin.setSelected = function( selected )

if selected ~= plugin.selected then

plugin.selected = selected;

if selected then

cp_frame:Show ();

else

cp_frame:Hide ();

end

end
end

I hope I have given enough info here if not just ask. Thanks for trying to help me understand lua.
 
08-27-09, 09:57 AM   #2
spiel2001
nUI's Author
 
spiel2001's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2008
Posts: 7,724
If it is all in the same file, then you can use the local variable "cp" instead of the global "cp_frame"

If the frame is being created in one file and accessed in another, you can access it like this...

local cp_frame = _G["cp_frame"];

which looks in the global table for the global variable named "cp_frame"
__________________

What people don't get is that I am, ultimately, an artist at heart.
My brush has two colors, 1 and 0, and my canvas is made of silicon.



Official nUI Web Site: http://www.nUIaddon.com
Official nUI Support Forum: http://forums.nUIaddon.com
My day job: http://www.presidio.com/
 
08-28-09, 08:14 AM   #3
rossman
A Cyclonian
 
rossman's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 39
This got me a little farther

I have been reading wowwiki and looking through other addons. I am still having trouble with this thing.
I get an error saying show is a nil value when the addon creates the panel or when I hit the button and the panel changes I get a hide is a nil value.
So it seems to be close.
Thank You for your help and patience.
 
08-28-09, 08:50 AM   #4
spiel2001
nUI's Author
 
spiel2001's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2008
Posts: 7,724
Why don't you post the code you have at present as an attachment in this thread, then we can look at the code and see where you're going wrong.
__________________

What people don't get is that I am, ultimately, an artist at heart.
My brush has two colors, 1 and 0, and my canvas is made of silicon.



Official nUI Web Site: http://www.nUIaddon.com
Official nUI Support Forum: http://forums.nUIaddon.com
My day job: http://www.presidio.com/
 
08-28-09, 11:25 AM   #5
rossman
A Cyclonian
 
rossman's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 39
ok here is the layout and infopanel is in attachment

layout lua

-- Create the Frame
local cp = CreateFrame("Frame","CargoPanel_Frame");
cp:SetPoint("CENTER",UIParent,"CENTER",0,0);
cp:SetWidth(250);
cp:SetHeight(25);
cp:SetAlpha(1.0);

local rep = cargoShip("|cffffb366Ara|r Reputations")
rep:SetPoint("TOPRIGHT", CargoPanel_Frame, "TOPRIGHT", 0, 0)


I get my layout without an issue.
I get it to be moved to the infopanel.
I get an error message when it trys to show the panel.
.UI_InfoPanel_CargoPanel\nUI_InfoPanel_CargoPanel.lua:137: attempt to call method 'show' (a nil value)

Thank You again
Attached Files
File Type: lua nUI_InfoPanel_CargoPanel.lua (4.6 KB, 1011 views)
 
08-28-09, 01:47 PM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Ah, you need to redefine CargoPanel_Frame in each function you want to access it in as they are local to the function unless you set it outside the function.

Code:
plugin.setSelected = function( selected )
	if selected ~= plugin.selected then
		plugin.selected = selected;
                          local CargoPanel_Frame = _G["CargoPanel_Frame"];
		if selected then
		CargoPanel_Frame:show()
		else
		CargoPanel_Frame:hide()
		end
	end
end
__________________
 
08-28-09, 10:58 PM   #7
rossman
A Cyclonian
 
rossman's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 39
Thank You. It is now working

Here is a SS of the infopanel in action. I have moved a few items out of Fortress and into my new LDB display info panel.
I am learning and thanks again for the help.
Attached Thumbnails
Click image for larger version

Name:	WoWScrnShot_082809_214809.jpg
Views:	1056
Size:	275.6 KB
ID:	3263  
 
 

WoWInterface » Featured Projects » nUI, MozzFullWorldMap and PartySpotter » Customization » nUI: Developer Chat » help getting info panel plugin to work

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