Thread: the _G changes.
View Single Post
09-24-10, 07:04 PM   #17
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Originally Posted by Grimsin View Post
I have made all the changes you suggested and still get errors as far as it thinking the db is a nil value certain changes make that happen and certain things break the /commands.
Because you didn't remove all of the db stuff, there is still some right in that code you posted.
Code:
local addonName, addon = ...

BINDING_HEADER_GRIMUI = "GrimUI"
BINDING_NAME_GTIPNOTES_PRINT = "Print ToolTip Note"
 
StaticPopupDialogs["GTipNotes"] = {
	button1 = "Set",
	button2 = "Cancel",
	hasEditBox = true,
	hideOnEscape = true,
	text = "Set a note for |cffff4488%s|r.",
	timeout = 0,
	whileDead = true,
	EditBoxOnEnterPressed = function(self, data)
		local note = self:GetText():trim()
		if note == "" then
			note = nil
		end
		GTipNotesDB[data] = note
		self:GetParent():Hide()
	end,
	EditBoxOnEscapePressed = function(self)
		self:GetParent():Hide()
	end,
	OnAccept = function(self, data)
		local note = _G[self:GetName() .. 'EditBox']:GetText():trim()
		if note == "" then
			note = nil
		end
		GTipNotesDB[data] = note
	end
}

SlashCmdList["GTIPNOTES_SHORTHAND"] = function(note)
	if UnitExists('target') then
		local name = UnitName('target')
		note = note:trim()
		if note == "" then
			note = GTipNotesDB[name]
		end
		StaticPopup_Show("GTipNotes", name, nil, name)
		if note then
			name = StaticPopup_Visible("GTipNotes")
			if name then
				_G[name .. 'EditBox']:SetText(note)
			end
		end
	else
		print("You must target something to add a note.")
	end
end
SLASH_GTIPNOTES_SHORTHAND1 = "/gtipnotes"

addon.RegisterEvent("TooltipNotes-Initialize", 'PLAYER_LOGIN', function(self, event)
	addon.UnregisterEvent(self, event)

	if type(GTipNotesDB) ~= 'table' then
		GTipNotesDB = { }
	end

	GameTooltip:HookScript('OnTooltipSetUnit', function(self)
		local note = GTipNotesDB[self:GetUnit()]
		if note then
			self:AddLine("|cffff4488Note:|r " .. note, 0.5, 0.5, 0.5, 1)
		end
	end)
end)

Originally Posted by Grimsin View Post
Im still really not understanding the use of _G now because almost everything that is broken, not just in the GrimUI has to do with _G. like baggins is borked and it has to do with the _G usage again and i just dont see why?

My entire move frames code is borked to in cata but im not even going there right now lol.
_G is just a table for the global namespace. Any error resulting from a line of code with _G[someVariableName] is because the object/value that has the name someVariableName on live in now gone, renamed, or significantly changed in beta. Pay attention to the error messages and check the values on the stack, this should easily get you to the relevant portion of Blizzard's code to track down the culprit.