PDA

View Full Version : UIDropDownMenu Problems


Unibus
14-02-2007, 12:55 AM
Hi

I'm trying to make a button, that when pressed it will show a Drop Down Menu with the current online friends in it.

This far i've made the button:


<Button name="WE_Friends" inherits="UIPanelButtonTemplate2" text="F" hidden="False" toplevel="true">
<Size>
<AbsDimension x="15" y="20"/>
</Size>
<Anchors>
<Anchor point="Right" relativeTo="WE_Exit" relativePoint="Left">
<Offset>
<AbsDimension x="0" y="0"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnClick>
MyDropDownMenuButton_OnClick();
</OnClick>
<OnEnter>
WE_DisplayTooltip("Friends",this);
</OnEnter>
<OnLeave>
We_Tooltip:Hide();
</OnLeave>
</Scripts>
</Button>


And the Drop Down Frame:


<Frame name="MyDropDownMenu" inherits="UIDropDownMenuTemplate" id="1">
<Scripts>
<OnLoad>
UIDropDownMenu_Initialize(this, MyDropDownMenu_OnLoad, "MENU");
</OnLoad>
</Scripts>
</Frame>


And the Lua Code for it:


function MyDropDownMenu_OnLoad()
local info = {};
info.text = "Friends Online";
info.notClickable = 1;
info.isTitle = 1;
UIDropDownMenu_AddButton(info);

local info = {};
info.text = "[Test Friend1]";
info.value = "OptionVariable";
info.func = WE_WhipserName();
UIDropDownMenu_AddButton(info);

local info = {};
info.text = "[Test Friend2]";
info.value = "OptionVariable";
info.func = WE_WhipserName();
UIDropDownMenu_AddButton(info);
end

function MyDropDownMenuButton_OnClick()
ToggleDropDownMenu(1, nil, MyDropDownMenu , WE_Exit, -10, 0);
end

function WE_WhipserName()
DEFAULT_CHAT_FRAME:AddMessage("It Works")
end


(Don't mind the WE_Exit anchor.)

But every time i load the addon, all the functions (info.func) are triggered. So i get "It Works"x2 when i load the interface and "It Works"x2 when i press the "WE_Friends" button. But no respons when i clikc an option in the dropdown menu.

Can anyone help me ?? plz :cry:

Thanks :grin:

Zillia Tippytoes
14-02-2007, 02:56 AM
Change all the lines that say...

info.func = WE_WhipserName();

to say...

info.func = "WE_WhipserName";

Unibus
14-02-2007, 12:34 PM
Okey, i've changed all the:

info.func = WE_WhipserName();
to say...
info.func = "WE_WhipserName";

but now i get a error ingame that says:

..\FrameXML\UIDropDownMenu.lua line 511:
attempt to call local 'func' (a string value)

Unibus
14-02-2007, 12:48 PM
Lol nvm I figured it out :P
Just needed to change

info.func = WE_WhipserName();
to:
info.func = WE_WhipserName; (not any "")

Thanks a lot :D

Rowaa
14-02-2007, 03:26 PM
If all your buttons always define exactly 3 same attributes text, value and func, please do not create a new table every time, just to trash it with reinit and function end - you'll get garbage in your memory for every click. Better either define info once or define it right before function start. In first case you'll generate only 1 garbage table per call vs. NumberOfButtons garbage tables and in second case you create table once and then reuse it always occupying memory for exactly one table and not generating any garbage at all.