Quantcast the _G changes. - WoWInterface
 
 
Thread Tools Display Modes
09-16-10, 11:59 PM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
the _G changes.

can someone explain this better. "The getglobal and setglobal functions are considerd deprecated, and have been removed from the C API's. In the interests of compatibility there remain lua implementations of both, but new code should be updated to use x = _G[globalName] and _G[globalName] = x instead."

what code should be updated? i think this is where the problems with my ui are but not exactly sure why does it mean things like this _G[prefix .. slots[id]] need to be changed? or _G[this:GetName().. ?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
 
09-17-10, 12:14 AM   #2
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
No, only setglobal(prefix .. slots[id], "SOMEVALUE") needs to be updated to _G[prefix .. slots[id]] = "SOMEVALUE".

If you didn't use setglobal or getglobal, then you shouldn't be worried.
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.
 
09-17-10, 07:52 AM   #3
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
hmmm, well im still confused then about one change or another. I get what appears to be the same value = nil error on a few different chunks of code. some of the chunks are as follows.

lua Code:
  1. local function CreateBorders(frame, prefix)
  2.     local border, start = { }, frame == CharacterFrame and 0 or 1
  3.     for id = start, #slots do
  4.         local frame = _G[prefix .. slots[id]]
  5.         local region = GetNormalTexture(frame:GetRegions())
  6.         local texture = frame:CreateTexture(nil, 'OVERLAY')
  7.         texture:SetTexture([[Interface\Buttons\UI-ActionButton-Border]])
  8.         texture:SetBlendMode('ADD')
  9.         texture:SetAlpha(0.8)
  10.         texture:SetPoint('TOPLEFT', region, -1, 3)
  11.         texture:SetPoint('BOTTOMRIGHT', region, 1, 0)
  12.         border[id] = texture
  13.     end
  14.     borders[frame] = border
  15. end
  16.  
  17. local function OnHide(self)
  18.     addon.UnregisterEvent(self, 'UNIT_INVENTORY_CHANGED')
  19. end
  20.  
  21. local function OnShow(self)
  22.     addon.RegisterEvent(self, 'UNIT_INVENTORY_CHANGED', UpdateItemQualityBorders)
  23.     UpdateItemQualityBorders(self, nil, self.unit)
  24. end
  25.  
  26. local function HookFrame(frame, prefix)
  27.     CreateBorders(frame, prefix)
  28.     frame:HookScript('OnHide', OnHide)
  29.     frame:HookScript('OnShow', OnShow)
  30. end
  31.  
  32. HookFrame(CharacterFrame, 'Character')
  33. CharacterFrame.unit = 'player'
  34.  
  35. if InspectFrame then
  36.     HookFrame(InspectFrame, 'Inspect')
  37. else
  38.     addon.RegisterEvent("Features-MonitorInspectUI", 'ADDON_LOADED', function(self, event, name)
  39.         if name ~= 'Blizzard_InspectUI' then return end
  40.         addon.UnregisterEvent(self, event)
  41.  
  42.         HookFrame(InspectFrame, 'Inspect')
  43.         if InspectFrame:IsShown() then
  44.             UpdateItemQualityBorders(InspectFrame, nil, InspectFrame.unit)
  45.         end
  46.     end)
  47. end

or this chunk

lua Code:
  1. hooksecurefunc('FriendsList_Update', function()
  2.     local buttons, button = FriendsFrameFriendsScrollFrame.buttons
  3.     local colors, CLASS = CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS, addon.CLASS
  4.     for index = 1, FriendsFrameFriendsScrollFrame.usedButtons do
  5.         button = buttons[index]
  6.         if button.buttonType == FRIENDS_BUTTON_TYPE_WOW then
  7.             local _, _, class, _, connected = GetFriendInfo(button.id)
  8.             if connected then
  9.                 local color = colors[CLASS[class]]
  10.                 button.name:SetTextColor(color.r, color.g, color.b)
  11.             end
  12.         end
  13.     end
  14. end)

and last but not least this chunk also
lua Code:
  1. _G.SlashCmdList["GTIPNOTES_SHORTHAND"] = function(input)
  2.     if not UnitExists("target") then
  3.         DEFAULT_CHAT_FRAME:AddMessage(TARGET_ERROR)
  4.         return
  5.     end
  6.     if type(input) ~= "string" or input:trim():len() == 0 then
  7.         if not StaticPopupDialogs["GTipNotes"] then
  8.             StaticPopupDialogs["GTipNotes"] = {
  9.                 text = nil,
  10.                 button1 = SET,
  11.                 button2 = CANCEL,
  12.                 whileDead = 1,
  13.                 hideOnEscape = 1,
  14.                 timeout = 0,
  15.                 OnShow = function()
  16.                     -- We have to do this onshow to reset the previous text
  17.                     local t = UnitExists("target") and UnitName("target") or ""
  18.                     _G[this:GetName().."EditBox"]:SetText(_G.GTipNotesDB[t] or "")
  19.                 end,
  20.                 OnHide = function()
  21.                     _G[this:GetName().."EditBox"]:SetText("")
  22.                 end,
  23.                 EditBoxOnEnterPressed = function()
  24.                     addNoteFromPopup(_G[this:GetParent():GetName().."EditBox"]:GetText())
  25.                     this:GetParent():Hide()
  26.                 end,
  27.                 EditBoxOnEscapePressed = function()
  28.                     this:GetParent():Hide()
  29.                 end,
  30.                 OnAccept = function()
  31.                     addNoteFromPopup(_G[this:GetParent():GetName().."EditBox"]:GetText())
  32.                 end,
  33.                 hasEditBox = 1,
  34.             }
  35.         end
  36.         StaticPopupDialogs["GTipNotes"].text = POPUP_TEXT:format(UnitName("target"))
  37.         StaticPopup_Show("GTipNotes")
  38.     else
  39.         local t = UnitName("target")
  40.         _G.GTipNotesDB[t] = input
  41.         DEFAULT_CHAT_FRAME:AddMessage(NOTE_SET:format(t, input))
  42.     end
  43. end

all works on live servers so it has to be the cata changes that caused this im just not sure which one or why.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
 
09-17-10, 08:55 AM   #4
IQgryn
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 46
Originally Posted by Grimsin View Post
hmmm, well im still confused then about one change or another. I get what appears to be the same value = nil error on a few different chunks of code. some of the chunks are as follows.

<snip>
Which lines are causing the nil errors?
 
09-17-10, 09:31 AM   #5
Beoko
A Cyclonian
 
Beoko's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 41
* The global variables this, event and arg1, arg2... have been removed. Event handlers and other callbacks must use the appropriate locals.
These changes are present as well.
 
09-17-10, 09:45 AM   #6
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
my use of "this" in the tooltips code i changed to self and got a way different error, i dont think the use of this in that instance is the same as what was changed? if so i should of been able to simply change this to self or at lest that was my understanding.

the exact line that it starts in the 3rd chunk of code is this one, it says "this" is a nil value
_G[this:GetName().."EditBox"]:SetText(_G.GTipNotesDB[t] or "")

in the first chunk of code it is this one, this one says "frame" is a nil value
local region = GetNormalTexture(frame:GetRegions())

in the 2nd chunk of code im not sure which line it was i have to go back and check.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
 
09-17-10, 10:13 AM   #7
IQgryn
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 46
Originally Posted by Grimsin View Post
my use of "this" in the tooltips code i changed to self and got a way different error, i dont think the use of this in that instance is the same as what was changed? if so i should of been able to simply change this to self or at lest that was my understanding.

the exact line that it starts in the 3rd chunk of code is this one, it says "this" is a nil value
_G[this:GetName().."EditBox"]:SetText(_G.GTipNotesDB[t] or "")

in the first chunk of code it is this one, this one says "frame" is a nil value
local region = GetNormalTexture(frame:GetRegions())

in the 2nd chunk of code im not sure which line it was i have to go back and check.
Unless you specifically declare a variable named this, any use of this is now invalid (and using it will cause nil errors). It's also not always just as simple as changing it to say self. That will usually work when you have a function definition of the form:
Code:
Frame:function()
Although even then, there can be problems. If your function is not declared like that (and the ones you posted aren't), you need to add a self parameter to the parameter list and update the code using the function to pass that along as well.

Note that if you add the parameter yourself, you don't have to call it self. You may use whatever name suits your fancy.
 
09-17-10, 11:43 AM   #8
Vrul
A Cobalt Mageweaver
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 235
Only the last error has anything to do with the changes to this, and only changing this to self won't fix it, you also need to update the function declarations to include that self is passed:
lua Code:
  1. _G.SlashCmdList["GTIPNOTES_SHORTHAND"] = function(input)
  2.     if not UnitExists('target') then
  3.         print(TARGET_ERROR)
  4.         return
  5.     end
  6.     input = input:trim()
  7.     if type(input) ~= 'string' or input == "" then
  8.         if not StaticPopupDialogs["GTipNotes"] then
  9.             StaticPopupDialogs["GTipNotes"] = {
  10.                 text = nil,
  11.                 button1 = SET,
  12.                 button2 = CANCEL,
  13.                 whileDead = 1,
  14.                 hideOnEscape = 1,
  15.                 timeout = 0,
  16.                 OnShow = function(self)
  17.                     -- We have to do this onshow to reset the previous text
  18.                     local name = UnitExists("target") and UnitName("target") or ""
  19.                     _G[self:GetName() .. "EditBox"]:SetText(_G.GTipNotesDB[name] or "")
  20.                 end,
  21.                 OnHide = function(self)
  22.                     _G[self:GetName() .. "EditBox"]:SetText("")
  23.                 end,
  24.                 EditBoxOnEnterPressed = function(self)
  25.                     addNoteFromPopup(_G[self:GetParent():GetName() .. "EditBox"]:GetText())
  26.                     self:GetParent():Hide()
  27.                 end,
  28.                 EditBoxOnEscapePressed = function(self)
  29.                     self:GetParent():Hide()
  30.                 end,
  31.                 OnAccept = function(self)
  32.                     addNoteFromPopup(_G[self:GetParent():GetName() .. "EditBox"]:GetText())
  33.                 end,
  34.                 hasEditBox = 1,
  35.             }
  36.         end
  37.         StaticPopupDialogs["GTipNotes"].text = POPUP_TEXT:format(UnitName('target'))
  38.         StaticPopup_Show("GTipNotes")
  39.     else
  40.         local name = UnitName('target')
  41.         _G.GTipNotesDB[name] = input
  42.         print(NOTE_SET:format(name, input))
  43.     end
  44. end

The issue with FriendsFrame code is that Blizzard changed it and no longer uses/sets FriendsFrameFriendsScrollFrame.usedButtons:
lua Code:
  1. hooksecurefunc('FriendsList_Update', function()
  2.     local buttons, button = FriendsFrameFriendsScrollFrame.buttons
  3.     local colors, CLASS = CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS, addon.CLASS
  4.     for index = 1, #buttons do
  5.         button = buttons[index]
  6.         if button:IsShown() then
  7.             if button.buttonType == FRIENDS_BUTTON_TYPE_WOW then
  8.                 local _, _, class, _, connected = GetFriendInfo(button.id)
  9.                 if connected then
  10.                     local color = colors[CLASS[class]]
  11.                     button.name:SetTextColor(color.r, color.g, color.b)
  12.                 end
  13.             end
  14.         else
  15.             break
  16.         end
  17.     end
  18. end)

Part of the problem with the first error is that the ammo slot was removed which is what slots[0] is, so remove the start variable and always begin with an id of 1:
lua Code:
  1. local function CreateBorders(frame, prefix)
  2.     local border = { }
  3.     for id = 1, #slots do
  4.         local frame = _G[prefix .. slots[id]]
  5.         local region = GetNormalTexture(frame:GetRegions())
  6.         local texture = frame:CreateTexture(nil, 'OVERLAY')
  7.         texture:SetTexture([[Interface\Buttons\UI-ActionButton-Border]])
  8.         texture:SetBlendMode('ADD')
  9.         texture:SetAlpha(0.8)
  10.         texture:SetPoint('TOPLEFT', region, -1, 3)
  11.         texture:SetPoint('BOTTOMRIGHT', region, 1, 0)
  12.         border[id] = texture
  13.     end
  14.     borders[frame] = border
  15. end

There may still be errors after making those changes, I don't have access to check, but at least you will be one step closer to fixing it.
 
 

WoWInterface » AddOns, Compilations, Macros » Cataclysm Beta » the _G changes.

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