WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Global Environmental Variables nil (https://www.wowinterface.com/forums/showthread.php?t=58355)

benots4 10-29-20 03:55 PM

Global Environmental Variables nil
 
I have a snipit of code I got from this site has broken by pre patch. The error I get now is nil value for ActionButton_GetPagedID(button).. button being nil. Seems like the environment function is returning a table of nil. local button = _G[barName .. 'Button' .. i] button is a table but nil. Have the Global environments changed? Know a way around this??



Original code
Code:

local ActionBars = {'Action','MultiBarBottomLeft','MultiBarBottomRight','MultiBarRight','MultiBarLeft'}
function PrintActions()
    for _, barName in pairs(ActionBars) do
        for i = 1, 12 do
            local button = _G[barName .. 'Button' .. i]
            local slot = ActionButton_GetPagedID(button) or ActionButton_CalculateAction(button) or button:GetAttribute('action') or 0
            if HasAction(slot) then
                local actionName, _
                local actionType, id = GetActionInfo(slot)
                if actionType == 'macro' then _, _ , id = GetMacroSpell(id) end
                if actionType == 'item' then
                    actionName = GetItemInfo(id)
                elseif actionType == 'spell' or (actionType == 'macro' and id) then
                    actionName = GetSpellInfo(id)
                end
                if actionName then
                    print(button:GetName(), actionType, (GetSpellLink(id)), actionName)
                end
            end
        end
    end
end


Xrystal 10-29-20 07:01 PM

The Bar/Button system has been updated now .. they are now part of the Mixin family which means some of these old functions need to be adjusted in some manner.

For example:
If you had a variable 'b' to hold the actionbutton in question which you then used ActionButton_GetPagedID to customise for your addon ... you now need to customise b:GetPagedID function.

This and many other files will show you other changes that have occurred recently.
https://www.townlong-yak.com/framexm...tionButton.lua

benots4 10-30-20 09:17 AM

Thanks!
Code:

local button = _G[barName .. 'Button' .. j]
local slot = button:GetPagedID() or button:CalculateAction() or button:GetAttribute('action')

works great.
although, could you explain why

Code:

function AMine:getListFromDB(DB)
  local items = {}
        if DB == nil then return "dbEmpty" end
        for index, value in pairs(DB)do
                tinsert(items, index)
        end
        return items       
 end

 button = _G[barName .. 'Button' .. j]

print(self.getListFromDB(button))

yields dbEmpty instead of a slot number?

Xrystal 10-30-20 09:52 AM

It would depend on how DB is filled ( that part is not shown in your code )

Locate the code that fills your DB table and make sure that what it is putting in there is the same as what is being used to get access to it.

SDPhantom 10-30-20 04:30 PM

From what I see, you're defining the function as AMine:getListFromDB() and calling as self.getListFromDB().

In this case, the first argument gets passed into the implicit variable self and DB gets the second argument, which is unspecified (automatically nil).
If you called with the colon notation, self gets passed in as the implicit variable and button will get assigned to DB.


For example, these function definitions are the same ...
Code:

function table:func(arg)
function table.func(self,arg)

... and these calls are the same.
Code:

table:func(arg)
table.func(table,arg)

You need to compensate for the argument shifting if you plan on using differing notations between definition and calling.

Xrystal 10-30-20 05:38 PM

Great catch SDPhantom. I didn't even spot that oversight. Nor the fact that DB was the variable passed in and not a DB that was filled elsewhere *sighs*


All times are GMT -6. The time now is 07:23 PM.

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