Thread Tools Display Modes
Prev Previous Post   Next Post Next
07-26-18, 05:20 PM   #1
Chokobo
A Murloc Raider
Join Date: Jul 2018
Posts: 9
Understanding this codes behavior.

First post here. I need a little help understanding what is going on if someone is willing.

Foremost I maintain an addon for personal use which just handles small little things to help me in my daily business.

Secondly I have never really delved into the realm of having to deal with secure code, or protected function, or hardware events etc. I will admit I am a complete novice in this area.

So, here is my question. I have this addon, it has one button. If you press the button, it should do 1 of 2 things via a function.

1.)
If "the table" is not populated, it will populate it with group ID's (From group finder), and it will filter those which are on auto accept. Now "the table" is populated.

2.) IF the table is populated, it will attempt to join the first group ID in the list of "the table"


What seems to be happening (In order):

1.) I press the button, There is no data, so it searches and populates.
2.) I press the button, Data Exists and it attempts to join (Protected) and I get an error "Interface action failed because of an Addon". Table is cleared, The function continues and repopulates the table
3.) I press the button, Data Exists and it attempts to join a group (Protected), and it succeeds.


What I dont understand is why this thing is not joining a group on the second press, but will on all subsequent presses. I know I am not going to win any awards for stellar programming here, but I would appreciate anyone willing to help me understand these secure functions and hardware events.

You can find the code here https://pastebin.com/fKmsNHQT

OR alternately here is the code in forum

Code:
ChokoTools = {}
 
--Standard Basic Button
ChokoTools.RandHop = CreateFrame("Button",nil,UIParent,"UIGoldBorderButtonTemplate")
ChokoTools.RandHop:SetSize(50,24)
ChokoTools.RandHop:SetPoint("BOTTOMLEFT",0,0)
ChokoTools.RandHop:SetText("HOP")
ChokoTools.RandHop:SetScript("OnClick", function(self, event, ...)
    ChokoTools:JoinRandomGroup()
end)
 
 
--Function: Search for groups with Auto Accept on. Join if we have data.
function ChokoTools:JoinRandomGroup()
    --Search already completed. (2nd Click)
    if (ChokoTools.FilteredIDs) and (#ChokoTools.FilteredIDs >= 1) then
        print("Joining...")
        C_LFGList.ApplyToGroup(ChokoTools.FilteredIDs[1], "", false, false, true)
        ChokoTools.FilteredIDs = {} --Reset table to empty
    end
   
    print("Searching...")
    ChokoTools.SearchResults = {}
    ChokoTools.FilteredIDs = {}
 
    --Search Groups (Taken and modified from "ServerHop" Addon)
    local lang = {}
    for k,v in pairs(C_LFGList.GetAvailableLanguageSearchFilter()) do lang[v]=true end
    C_LFGList.Search(6,LFGListSearchPanel_ParseSearchTerms(""),0,0,lang) --Search "Custom" groups
   
    --Get Search Results
    c, ChokoTools.SearchResults = C_LFGList.GetSearchResults()
   
    --Iterate through search results
    for i=1,#ChokoTools.SearchResults do
        local id, _, _, _, _, _, _, _, _, _, _, _, _, _, autoinv = C_LFGList.GetSearchResultInfo(ChokoTools.SearchResults[i])
        if autoinv == true then
            table.insert(ChokoTools.FilteredIDs,id)
        end
    end
end

Last edited by Chokobo : 07-26-18 at 05:24 PM.
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Understanding this codes behavior.

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