WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Fixing up an abandoned addon (https://www.wowinterface.com/forums/showthread.php?t=56566)

Puddycat 08-17-18 09:26 AM

Fixing up an abandoned addon
 
Hi, I am trying to update an addon that was abandoned in 2011.
It was working till patch 8.0 though.

I think there are 2 main problems.
SetText doesn't seem to be sending over any text.

Code:

autoMacroOptionsTitle:SetText(autoMacroStrings.Title);
And I am not sure it is reading all the channels.
My debuff only shows channel

Code:

function ChannelsMenu_Initialize()
        local channels = { GetChannelList(); }
        local channels_user = {};
        local iter = 0;
        for i,title in ipairs(channels) do
                if i % 2 ~= 0 then
                        iter = iter + 1;
                        channels_user[iter] = title;
                else
                        channels_user[iter] = channels_user[iter] .. ". " .. title;
                        ShowDebug("Found channel " .. channels_user[iter]);
                end
        end
        for i, title in ipairs(channels_user) do
                local info = UIDropDownMenu_CreateInfo();
                info.text = title;
                info.value = i;
                info.owner = ChannelsDropdown;
                info.func = function(self) OnChannelsMenuClick(self) end;
                UIDropDownMenu_AddButton(info);
        end
end

function OnChannelsMenuClick(self)
        UIDropDownMenu_SetSelectedValue(self.owner, self.value);
        local menuText = UIDropDownMenu_GetText(ChannelsDropdown);
        ShowDebug("Selected channel: [" .. self.value .. "] : " .. menuText);
        autoMacroOptionsChannelButton:SetText(menuText);
end

I have uploaded the entire addon to Github aswell: https://github.com/DamienShahan/autoMacro/tree/master

I would greatly appreciate any help.

PhoenixPower 08-23-18 06:34 AM

The reason why the code is erroring is that GetChannelList() now returns 3 values per channel rather than 2. Also changed to a recursive style, adding another if statement with a modulus comparison seemed ugly. And I don't think anything is wrong with the SetText code, it just never got executed because it happens after the error trying to initialize the dropdown menu. Just replace the original ChannelsMenu_Initialize with this one and you should be good to go.

Lua Code:
  1. function ChannelsMenu_Initialize()
  2.     local function AddChannelsRecursively(id, name, disabled, ...)
  3.         local title = id .. ". " .. name;
  4.         ShowDebug("Found channel " .. title);
  5.  
  6.         local info = UIDropDownMenu_CreateInfo();
  7.         info.text = title;
  8.         info.value = id;
  9.         info.owner = ChannelsDropdown;
  10.         info.func = OnChannelsMenuClick;
  11.         UIDropDownMenu_AddButton(info);
  12.  
  13.         if ... then return AddChannelsRecursively(...) end
  14.     end
  15.     AddChannelsRecursively(GetChannelList());
  16. end


All times are GMT -6. The time now is 09:30 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI