1. Hi,

    I've been trying to add code for a drop down menu for a couple of days but I can't seem to get it to work. I've followed the steps at http://www.wowwiki.com/Using_UIDropDownMenu but I'm not getting any results. I've run my code through XML nanny and I've double check the lua several times but I'm still not able to find any faults. Here is the code from my files...

        <Frames>
            <Button name="MyDropDownMenuButton">
                <Scripts>
                    <OnLoad>
                        UIDropDownMenu_Initialize(this, MyDropDownMenu_OnLoad)
                        print("UIDropDownMenu_Initialize")
                    </OnLoad>
                    <OnClick>
                        MyDropDownMenuButton_OnClick()
                        print("OnClick")
                    </OnClick>
                </Scripts>
            </Button>
        </Frames>
    
     function MyDropDownMenu_OnLoad()
        info        = {};
        info.text   = "This is an option in the menu.";
        info.value  = "OptionVariable";
        info.func   = FunctionCalledWhenOptionIsClicked
    
        UIDropDownMenu_AddButton(info);
        print("MyDropDownMenu_OnLoad");
     end
    
     function MyDropDownMenuButton_OnClick()
        ToggleDropDownMenu(1, nil, MyDropDownMenu, MyDropDownMenuButton, 0, 0);
     end
    

    What could I be missing here?

    1. Is your addon being loaded
    2. What does happen

    "Is your addon being loaded"

    Yes, it loads without any errors.

    "What does happen"

    It displays the (limited) functionality that it did before I added the code for the drop down menu. I can drag the window, click on the close button to close the window, and use two slash commands to show and hide the window.

    Do you need me to zip and link the current code?

    I don't know that I'll have much time to look at it in the next week or so.. any more information you can provide would be better.. so might as well start with posting the code.

    I'm thinking that this particular issue was caused by the graphics I was using for the border and background "covering" the drop down menu button. I went back and reworked the the border and background with something less fancy and the problem was pretty much "solved". I also went back to the book and re-read chapter 23 and the example code. I figured I wasn't that far into it to just scrap what I had and start from scratch and it worked. The gears are moving once again. :)

    My next question would be how to get the drop down menu button to resemble the square button with the down arrow rather then the regular button image?

    Thanks,

    -z

    The following code does (I think) what you want:

     if not DropDownMenuTest then
       CreateFrame("Frame", "DropDownMenuTest", UIParent, "UIDropDownMenuTemplate")
     end
    
     DropDownMenuTest:ClearAllPoints()
     DropDownMenuTest:SetPoint("CENTER", 0, 0)
     DropDownMenuTest:Show()
    
     local items = {
       "Alpha",
       "Beta",
       "Gamma",
       "Delta",
     }
    
     local function OnClick(self)
       UIDropDownMenu_SetSelectedID(DropDownMenuTest, self:GetID())
     end
    
     local function initialize(self, level)
       local info = UIDropDownMenu_CreateInfo()
       for k,v in pairs(items) do
         info = UIDropDownMenu_CreateInfo()
         info.text = v
         info.value = v
         info.func = OnClick
         UIDropDownMenu_AddButton(info, level)
       end
     end
    
    
     UIDropDownMenu_Initialize(DropDownMenuTest, initialize)
     UIDropDownMenu_SetWidth(DropDownMenuTest, 100);
     UIDropDownMenu_SetButtonWidth(DropDownMenuTest, 124)
     UIDropDownMenu_SetSelectedID(DropDownMenuTest, 1)
     UIDropDownMenu_JustifyText(DropDownMenuTest, "LEFT")
    

    I found the above to be very helpful in creating the dropdown menu quickly and easily. So much easier than creating the buttons individually and setting the attributes attributes so the menu works like the one based on the code above. I did create the frame with:

    mypointer = CreateFrame("Frame", "DropDownMenuTest", UIParent, "UIDropDownMenuTemplate")

    where the pointer can be interchangable with the name:

    DropDownMenuTest:ClearAllPoints() is the same as mypointer:ClearAllPoints()

    I wanted a variable that I could use to set the buttons in the menu and to retrieve their current settings. I have managed to figure out how the code above names the buttons and sets their id numbers, but I am having a heck of a time getting or setting any information on the buttons (ie. DropDownList1Button1). If I want to run a function on DropDownList1Button3 pressed and change its settings, I need to know what its current settings are and how to change them. I can't seem to grab a "pointer" to the button.

    Depending on which button is selected, I need to be able to set a variable that remembers the setting so that the button is selected next time the $parent is opened (after a UI reload) until it is eventually changed by the player. I need to be able to capture the active selection and also disable selections that are not available to the given player.

    In short, how do I get and set information about the buttons that were set with the : UIDropDownMenu_AddButton(info, level)

    How would I disable DropDownList1Button3, or check for the current button that is selected?

    I am sure there is something very simple that I am missing. I should be able to query the buttons and set them, but I cannot figure it out at the moment. Heading out for a few days on a trip. May or may not get online during that time. I know for sure I will not be online while in Ascension Island Tuesday ;-)

    Edit: Do I use the selected ID to run functions then delete the DropDownList1 and recreate it every time a button is selected, or simply re-initialize it using something like: UIDropDownMenuInitialize(DropDownMenuTest, initialize(1)). Create a table and keep track of all inputs through the ID that is passed, then use the initialize function and the UIDropDownMenuSetSelectedID(DropDownMenuTest, tableValueofselected), using the table values to manipulate the "info" values that way? (May be why you reuse the "info" in initialize to minimize clutter?)

    Is there a reason the extensive chapter on dropdown menus in the book doesn't make any of this clear? It doesn't really get any easier than using the two methods I present in that chapter.

    Your questions are very specific to your own implementation so I'm not sure how to answer them. I would never code a menu in the way you're describing.. I would use the methods I use in the chapter on this topic, where these sorts of things are discussed.

    Do you have a specific more general question I can answer?

    The book is a bit large to carry with me while traveling. I'll check it out when I get home and order the latest edition. I'll get back to you if I still have a question, or explain my problem and solution a bit better.

    After using the book and playing around a bit, things finally made sense and it is working now. It is an initialization issue. Getting the initialization to run at the proper times after the values are manipulated by the OnClick() was all that was needed. I simply called a function from the main body (after values changed) and it called the initialization. When ever the frame opened, the menu operated properly. My misconception came from not understanding the variables were being initialized repeatedly and the values had to be linked in the initialization function. I just didn't see it in the book my first time through. "Gettin' old ain't for sissies!"

    Great, glad to hear it!