Quantcast
Global Environmental Variables nil - WoWInterface
Thread Tools Display Modes
10-29-20, 03:55 PM   #1
benots4
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 20
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
  Reply With Quote
10-29-20, 07:01 PM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,535
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
__________________
  Reply With Quote
10-30-20, 09:17 AM   #3
benots4
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 20
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?
  Reply With Quote
10-30-20, 09:52 AM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,535
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.
__________________
  Reply With Quote
10-30-20, 04:30 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,979
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.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-30-20 at 04:32 PM.
  Reply With Quote
10-30-20, 05:38 PM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,535
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*
__________________
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Global Environmental Variables nil

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