Thread Tools Display Modes
12-27-12, 07:13 PM   #1
skarie
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2011
Posts: 37
Need expert advice and The Klaxxi faction ID

Halo,

As I am new to wow programming, I need some expert advice on how to improve this code snippet below. I am concerned about the performance issue. Is there a better (more efficient way) to achieve the same goal. I am trying to track reputations. So far, it runs fine except for The Klaxxi faction. Only the name ("The Klaxxi") is displayed and nothing else.

Code:
--faciton ids
local repTable = {1341, 1269, 1270, 1337, 1359}

local fEvent = {}
local repFrame = {}
local rName = {}

for k,v in pairs(repTable) do 
	fEvent[k] = CreateFrame("Frame",nil, UIParent)
	fEvent[k]:SetSize(140,15)
	fEvent[k]:SetFrameStrata("LOW")

	if ( k == 1) then 
		fEvent[k]:SetPoint("TOP",Minimap,"BOTTOM",0,-25)
	else
		fEvent[k]:SetPoint("TOP",fEvent[k-1],"BOTTOM",0,-2)
	end

        --CreateBD creates back drop with with black background and alpha .7
	F.CreateBD(fEvent[k],.7)
	
	repFrame[k] = CreateFrame("StatusBar",nil,self)
	repFrame[k]:SetFrameStrata("BACKGROUND")
	repFrame[k]:SetAllPoints(fEvent[k])
	repFrame[k]:SetStatusBarTexture(C.media.texture)
	repFrame[k]:SetStatusBarColor(1, 1, 1, 1)
	repFrame[k]:SetReverseFill(false)
	repFrame[k]:RegisterEvent("UPDATE_FACTION")
	
	rName[k] = F.CreateFS(fEvent[k], 8,"LEFT")
	rName[k]:SetPoint("LEFT",fEvent[k],"LEFT",2,0)
	
	repFrame[k]:SetScript("OnEvent", function(self,event,...)
		local name, _, standing, barMin, _, barValue, _, _, _, _, _, _, _ = GetFactionInfoByID(v)
		local  curr
		curr = barValue - barMin
		
		if( standing == 8) then
                        --when exalted, change text color
			rName[k]:SetText("|cFFFF9955"..name)
		else
			rName[k]:SetText("|r"..name)
			repFrame[k]:SetMinMaxValues(0,barMin)
			repFrame[k]:SetValue(barMin - curr)
		end
	end)
 end
What is the The Klaxxi faction id? I use faction id provided by wowhead.com. But that doesnt seem to work.
  Reply With Quote
12-27-12, 08:29 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If it's showing the name ("The Klaxxi") then you are getting the name via the API call, which means you are using the correct faction ID.

The only thing that jumps out at me is that you are using pairs instead of ipairs. pairs returns key/value pairs in undefined order, so you won't get 1/1341 and then 2/1269 and so on; you could get 2/1269 and then 5/1359 and then 3/1270, for example. Since you are using the indices (keys) inside your for-loop in a way that clearly expects the key/value pairs to be processed in sequential order, this is likely causing your problem, and you are almost certainly getting a Lua error. Simply switching to ipairs may solve your problem.

However, if you do not already have BugSack installed and enabled, go get it. The built-in errror display is (a) disabled by default, (b) annoyingly intrusive, and (c) cannot show you errors that occur during the initial loading process, which is when the majority of errors will occur while you are developing an addon.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-27-12, 11:21 PM   #3
skarie
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2011
Posts: 37
Hi Phanx,

Thanks for taking the time to look at my codes.

I changed pairs to ipairs and installed bugstack. No error is generated. However, that doesn't do the trick. The results are still the same. Its so strange that all the other reps i am tracking show up correctly, except for The Klaxxi. Maybe I should use other API method to get the reps.
  Reply With Quote
12-28-12, 12:50 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
After taking another look, I see several places where you're calling functions like F.CreateBD and F.CreateFS that are not defined anywhere in your code, which means that either:

(a) the code you posted is not your real code, or not all of your real code, in which case, please post your entire, actual code if you want help with it, or

(b) you based your code on something you copied and pasted from somewhere, but didn't remove the references to parts you didn't keep, and you forgot to restart WoW after installing BugSack, because attempting to call a function that is not defined anywhere will always trigger a Lua error, without exception, in which case, try removing those references and restarting WoW if you haven't yet so that BugSack can actually catch the errors that are occurring.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 12-28-12 at 01:11 AM.
  Reply With Quote
12-28-12, 01:17 AM   #5
skarie
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2011
Posts: 37
Originally Posted by Phanx View Post
After taking another look, I see several places where you're calling functions like F.CreateBD and F.CreateFS that are not defined anywhere in your code, which means that either:

(a) the code you posted is not your real code, or not all of your real code, in which case, please post your entire, actual code if you want help with it, or

(b) you based your code on something you copied and pasted from somewhere, but didn't remove the references to parts you didn't keep, and you forgot to restart WoW after installing BugSack, because attempting to call a function that is not defined anywhere will always trigger a Lua error, without exception, in which case, try removing those references and restarting WoW if you haven't yet so that BugSack can actually catch the errors that are occurring.
You're correct..CreateDB and CreateFS is defined some place else...but here I modified the lua to include both functions in same file.

Code:
--local F, C, L = unpack(select(2, ...))

local CreateBD = function(f, a)
	f:SetBackdrop({
		--bgFile = C.media.backdrop,
		bgFile = "",
		--edgeFile = C.media.backdrop,
		edgeFile = "",
		edgeSize = 1,
	})
	f:SetBackdropColor(0, 0, 0, a or .5)
	--f:SetBackdropColor(0.2, 0.36, 0.45, a or .5)
	f:SetBackdropBorderColor(0, 0, 0)
end

local CreateFS = function(parent, size, justify)
    local f = parent:CreateFontString(nil, "OVERLAY")
    --f:SetFont(C.media.font, size, "OUTLINEMONOCHROME")
	f:SetFont(STANDARD_TEXT_FONT, size, "OUTLINEMONOCHROME")
	f:SetShadowColor(0, 0, 0, 0)
    if(justify) then f:SetJustifyH(justify) end
    return f
end

local repTable = {1341, 1269, 1270, 1337, 1359}

local fEvent = {}
local repFrame = {}
local rName = {}

for k,v in ipairs(repTable) do 
	fEvent[k] = CreateFrame("Frame",nil, UIParent)
	fEvent[k]:SetSize(140,15)
	fEvent[k]:SetFrameStrata("LOW")

	if ( k == 1) then 
		fEvent[k]:SetPoint("TOP",Minimap,"BOTTOM",0,-25)
	else
		fEvent[k]:SetPoint("TOP",fEvent[k-1],"BOTTOM",0,-2)
	end
	--F.CreateBD(fEvent[k],.7)
	CreateBD(fEvent[k],.7)
	
	repFrame[k] = CreateFrame("StatusBar",nil,self)
	repFrame[k]:SetFrameStrata("BACKGROUND")
	repFrame[k]:SetAllPoints(fEvent[k])
	repFrame[k]:SetStatusBarTexture(C.media.texture)
	repFrame[k]:SetStatusBarColor(1, 1, 1, 1)
	repFrame[k]:SetReverseFill(true)
	repFrame[k]:RegisterEvent("UPDATE_FACTION")
	
	rName[k] = CreateFS(fEvent[k], 8,"LEFT")
	rName[k]:SetPoint("LEFT",fEvent[k],"LEFT",2,0)
	
	repFrame[k]:SetScript("OnEvent", function(self,event,...)
		local name, _, standing, barMin, _, barValue, _, _, _, _, _, _, _ = GetFactionInfoByID(v)
		local  curr
		curr = barValue - barMin
		
		if( standing == 8) then
			rName[k]:SetText("|cFFFF9955"..name)
		else
			rName[k]:SetText("|r"..name)
			repFrame[k]:SetMinMaxValues(0,barMin)
			repFrame[k]:SetValue(barMin - curr)
		end
	end)
 end

Last edited by skarie : 12-28-12 at 01:19 AM.
  Reply With Quote
12-28-12, 02:07 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I don't know what, specifically, was wrong with your code, but I ended up just rewriting it from scratch, and this works flawlessly. I included some comments to indicate where to insert calls to your backdrop and border functions if you want.

Code:
local factions = { 1341, 1269, 1270, 1337, 1359 }

local bars = {}

-- Feel free to remove this and replace it with your backdrop function:
local BACKDROP = {
	bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tile = true, tileSize = 16,
	edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], edgeSize = 16,
	insets = { left = 5, right = 5, top = 5, right = 5 },
}

local function OnEvent(self, event, ...)
	local name, _, standing, barMin, barMax, barValue = GetFactionInfoByID(self.factionID)
	self:SetMinMaxValues(barMin, barMax)
	self:SetValue(barValue)

	local color = FACTION_BAR_COLORS[standing]
	self:SetStatusBarColor(color.r, color.g, color.b)

	self.text:SetText(name)
	if standing == 8 then
		self.text:SetTextColor(1, 0.6, 0.33)
	else
		self.text:SetTextColor(1, 1, 1)
	end
end

-- Feel free to remove this function if you don't want mouse interactivity:
local function OnEnter(self)
	local _, _, _, barMin, barMax, barValue = GetFactionInfoByID(self.factionID)
	self.text:SetFormattedText("%d/%d", barValue - barMin, barMax - barMin)
end

-- Feel free to remove this function if you don't want mouse interactivity:
local function OnLeave(self)
	local name = GetFactionInfoByID(self.factionID)
	self.text:SetText(name)
end

for i, factionID in ipairs(factions) do
	local bar = CreateFrame("StatusBar", nil, UIParent)
	bar:SetPoint("TOP", i>1 and bars[i-1] or Minimap, "BOTTOM", 0, i>1 and -8 or -24)
	bar:SetSize(162, 14)
	bars[i] = bar

	-- Feel free to remove this section and replace it with a call to your backdrop function:
	local bg = bar:CreateTexture(nil, "BACKGROUND")
	bg:SetAllPoints(true)
	bg:SetTexture(0, 0, 0, 0.7)
	bar.bg = bg

	bar:SetStatusBarTexture([[Interface/TargetingFrame/UI-StatusBar]])
	bar:GetStatusBarTexture():SetDrawLayer("BORDER")

	-- Feel free to remove this section and replace it with a call to your border function
	local left = bar:CreateTexture(nil, "ARTWORK")
	left:SetTexture([[Interface\AchievementFrame\UI-Achievement-ProgressBar-Border]])
	left:SetTexCoord(0, 0.0625, 0, 0.75)
	left:SetPoint("TOPLEFT", -6, 5)
	left:SetPoint("BOTTOMLEFT", -6, -5)
	left:SetWidth(16)
	bar.left = left
	local right = bar:CreateTexture(nil, "ARTWORK")
	right:SetTexture([[Interface\AchievementFrame\UI-Achievement-ProgressBar-Border]])
	right:SetTexCoord(0.812, 0.8745, 0, 0.75)
	right:SetPoint("TOPRIGHT", 6, 5)
	right:SetPoint("BOTTOMRIGHT", 6, -5)
	right:SetWidth(16)
	bar.right = right
	local center = bar:CreateTexture(nil, "ARTWORK")
	center:SetTexture([[Interface\AchievementFrame\UI-Achievement-ProgressBar-Border]])
	center:SetTexCoord(0.0625, 0.812, 0, 0.75)
	center:SetPoint("TOPLEFT", left, "TOPRIGHT")
	center:SetPoint("BOTTOMRIGHT", right, "BOTTOMLEFT")
	center:SetWidth(16)
	bar.center = center
	-- End of border section

	local text = bar:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
	text:SetPoint("CENTER")
	bar.text = text

	bar.factionID = factionID
	bar:SetScript("OnEvent", OnEvent)
	bar:RegisterEvent("UPDATE_FACTION")

	-- Feel free to remove this section if you don't want mouse interactivity:
	bar:EnableMouse(true)
	bar:SetScript("OnEnter", OnEnter)
	bar:SetScript("OnLeave", OnLeave)
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-28-12, 02:35 AM   #7
skarie
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2011
Posts: 37
Thumbs up

Originally Posted by Phanx View Post
I don't know what, specifically, was wrong with your code, but I ended up just rewriting it from scratch, and this works flawlessly. I included some comments to indicate where to insert calls to your backdrop and border functions if you want.
You are so awesome !! I am gonna take a good look and learn from your codes. Thanks again.

Did you try to run my codes and get the same result (my result that is)? I am still very new to wow programming and certainly appreciate greatly all the help I get. :-)

Cheer ! This beer on me.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Need expert advice and The Klaxxi faction ID


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