Thread Tools Display Modes
11-02-14, 10:48 AM   #1
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Stat Switching Unexpectedly

Below is my current Stat that keeps switching from Melee to Caster for my hunter.

This seems to only happens when I take a portal from Shrine.

Here is the playerRole Function:
Code:
function nData:UpdatePlayerRole()
	
	if UnitLevel("player") >= 10 then
		local _, class = UnitClass("player")
		local spec = GetSpecialization()
		local specRole = GetSpecializationRole(spec) -- no need for a giant table that must be maintained by hand		
		if specRole == "TANK" then
			playerRole = "Tank"
		elseif specRole == "HEALER" then
			playerRole = "Caster"
		elseif specRole == "DAMAGER" then
			if UnitPowerType("player") == SPELL_POWER_MANA then
				if (class == "PALADIN" and spec == 3) or (class == "SHAMAN" and spec == 2) then 
					playerRole = "Melee"
				else
					playerRole = "Caster"
				end
			else
				playerRole = "Melee"
			end
		elseif specRole == nil then
			playerRole = nil -- no spec
		end
	else
		return
	end
end
Here is the Stat:
Code:
local nData = LibStub("AceAddon-3.0"):GetAddon("nData")

------------------------------------------------------------------------
--	 Statistics Plugin Functions
------------------------------------------------------------------------
nData.pluginConstructors["stat1"] = function()

	db = nData.db.profile
	
	local plugin = CreateFrame('Frame', nil, Datapanel)
	plugin:RegisterEvent("PLAYER_ENTERING_WORLD")
	plugin:SetFrameStrata("BACKGROUND")
	plugin:SetFrameLevel(3)
	plugin:EnableMouse(true)

	local Text  = plugin:CreateFontString(nil, "OVERLAY")
	Text:SetFont(db.font, db.fontSize,'THINOUTLINE')
	nData:PlacePlugin(db.stat1, Text)

	local playerClass, englishClass = UnitClass("player");

	local function ShowTooltip(self)
		if InCombatLockdown() then return end
	
		local anchor, panel, xoff, yoff = nData:DataTextTooltipAnchor(Text)
		GameTooltip:SetOwner(panel, anchor, xoff, yoff)
		GameTooltip:ClearLines()
		GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Statistics")
		GameTooltip:AddLine' '		
		if UnitLevel("player") > 10 then
				
			if playerRole == "Tank" then
				local Total_Dodge = GetDodgeChance()
				local Total_Parry = GetParryChance()
				local Total_Block = GetBlockChance()
				
				GameTooltip:AddLine(STAT_CATEGORY_DEFENSE)
				GameTooltip:AddDoubleLine(DODGE_CHANCE, format("%.2f%%", Total_Dodge),1,1,1)
				GameTooltip:AddDoubleLine(PARRY_CHANCE, format("%.2f%%", Total_Parry),1,1,1)
				GameTooltip:AddDoubleLine(BLOCK_CHANCE, format("%.2f%%", Total_Block),1,1,1)				
				
			elseif playerRole == "Caster" then
				local SC = GetSpellCritChance("2")
				local Total_Spell_Haste = UnitSpellHaste("player")
				local base, casting = GetManaRegen()
				local manaRegenString = "%d / %d"				
				
				GameTooltip:AddLine(STAT_CATEGORY_SPELL)
				GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", SC), 1, 1, 1)
				GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Spell_Haste), 1, 1, 1)		
				GameTooltip:AddDoubleLine(MANA_REGEN, format(manaRegenString, base * 5, casting * 5), 1, 1, 1)

			elseif playerRole == "Melee" then
			
				if englishClass == "HUNTER" then
					local Total_Range_Haste = GetRangedHaste("player")
					local Range_Armor_Pen = GetArmorPenetration();
					local Range_Crit = GetRangedCritChance("25")
					local speed = UnitRangedDamage("player")
					local Total_Range_Speed = speed
					
					GameTooltip:AddLine(STAT_CATEGORY_RANGED)					
					GameTooltip:AddDoubleLine("Armor Penetration", format("%.2f%%", Range_Armor_Pen), 1, 1, 1)
					GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", Range_Crit), 1, 1, 1)	
					GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Range_Haste), 1, 1, 1)
					GameTooltip:AddDoubleLine(STAT_ATTACK_SPEED, format("%.2f".." (sec)", Total_Range_Speed), 1, 1, 1)					
				else
					local Melee_Crit = GetCritChance("player")
					local Melee_Armor_Pen = GetArmorPenetration();
					local Total_Melee_Haste = GetMeleeHaste("player")
					local mainSpeed = UnitAttackSpeed("player");
					local MH = mainSpeed
					
					GameTooltip:AddLine(STAT_CATEGORY_MELEE)
					GameTooltip:AddDoubleLine("Armor Penetration", format("%.2f%%", Melee_Armor_Pen), 1, 1, 1)
					GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", Melee_Crit), 1, 1, 1)		
					GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Melee_Haste), 1, 1, 1)
					GameTooltip:AddDoubleLine(STAT_ATTACK_SPEED, format("%.2f".." (sec)", MH), 1, 1, 1)
				end
			end
			GameTooltip:AddLine' '
			GameTooltip:AddLine(STAT_CATEGORY_GENERAL)
			local masteryspell
			local Multi_Strike = GetMultistrike();
			local Life_Steal = GetLifesteal();
			--local Versatility = GetVersatility();
			local Versatility_Damage_Bonus = GetCombatRatingBonus(CR_VERSATILITY_DAMAGE_DONE) + GetVersatilityBonus(CR_VERSATILITY_DAMAGE_DONE);
			local Avoidance = GetAvoidance();
			local bonusArmor, isNegatedForSpec = UnitBonusArmor("player");
			
			GameTooltip:AddDoubleLine(STAT_BONUS_ARMOR, format("%s", bonusArmor), 1, 1, 1)
			GameTooltip:AddDoubleLine(STAT_MULTISTRIKE, format("%.2f%%", Multi_Strike), 1, 1, 1)
			GameTooltip:AddDoubleLine(STAT_LIFESTEAL, format("%.2f%%", Life_Steal), 1, 1, 1)
			GameTooltip:AddDoubleLine(STAT_VERSATILITY, format("%.2f%%", Versatility_Damage_Bonus), 1, 1, 1)
			--GameTooltip:AddDoubleLine(STAT_VERSATILITY, format("%d", Versatility), 1, 1, 1)
			GameTooltip:AddDoubleLine(STAT_AVOIDANCE, format("%.2f%%", Avoidance), 1, 1, 1)
			if GetCombatRating(CR_MASTERY) ~= 0 and GetSpecialization() then
				if englishClass == "DRUID" then
					if playerRole == "Melee" then
						masteryspell = select(2, GetSpecializationMasterySpells(GetSpecialization()))
					elseif playerRole == "Tank" then
						masteryspell = select(1, GetSpecializationMasterySpells(GetSpecialization()))
					else
						masteryspell = GetSpecializationMasterySpells(GetSpecialization())
					end
				else
					masteryspell = GetSpecializationMasterySpells(GetSpecialization())
				end
				

				local Mastery = GetMasteryEffect("player")
				local masteryName, _, _, _, _, _, _, _, _ = GetSpellInfo(masteryspell)
				if masteryName then
					GameTooltip:AddDoubleLine(masteryName, format("%.2f%%", Mastery), 1, 1, 1)
				end
			end			
		else
			GameTooltip:AddLine("No Stats Available unit Level 10")
		end

		GameTooltip:Show()
	end

	local function UpdateTank(self)
		local armorString = hexa..ARMOR..hexb..": "
		local displayNumberString = string.join("", "%s", "%d|r");
		local base, effectiveArmor, armor, posBuff, negBuff = UnitArmor("player");
		local Melee_Reduction = effectiveArmor
		
		Text:SetFormattedText(displayNumberString, armorString, effectiveArmor)
		--Setup Tooltip
		self:SetAllPoints(Text)
	end

	local function UpdateCaster(self)
		local spellpwr = GetSpellBonusDamage("2");
		local displayNumberString = string.join("", "%s", "%d|r");
		
		Text:SetFormattedText(displayNumberString, hexa.."SP: "..hexb, spellpwr)
		--Setup Tooltip
		self:SetAllPoints(Text)
	end

	local function UpdateMelee(self)	
		local displayNumberString = string.join("", "%s", "%d|r");
			
		if englishClass == "HUNTER" then
			local base, posBuff, negBuff = UnitRangedAttackPower("player")
			local Range_AP = base + posBuff + negBuff	
			pwr = Range_AP
		else
			local base, posBuff, negBuff = UnitAttackPower("player")
			local Melee_AP = base + posBuff + negBuff		
			pwr = Melee_AP
		end
		
		Text:SetFormattedText(displayNumberString, hexa.."AP: "..hexb, pwr)      
		--Setup Tooltip
		self:SetAllPoints(Text)
	end

	-- initial delay for update (let the ui load)
	local int = 5	
	local function Update(self, t)
		int = int - t
		if int > 0 then return end
		if UnitLevel("player") >= 10 then
			if playerRole == "Tank" then 
				UpdateTank(self)
			elseif playerRole == "Caster" then
				UpdateCaster(self)
			elseif playerRole == "Melee" then
				UpdateMelee(self)
			end
		else
			Text:SetText(hexa.."No Stats"..hexb)
		end
		int = 2
	end

	plugin:SetScript("OnEnter", function() ShowTooltip(plugin) end)
	plugin:SetScript("OnLeave", function() GameTooltip:Hide() end)
	plugin:SetScript("OnUpdate", Update)
	Update(plugin, 10)

	return plugin -- important!
end
Any help with this would be great.

Thanks
Coke
  Reply With Quote
11-02-14, 02:22 PM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
I take it you debugged it and it highlights that it is passing true for mana in hunters for a split second somewhere during that port before realising it is not really mana ?

Although maybe it is best to check for the class and spec to decide on damager type rather than rely on the power source. Just a thought.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 11-02-14 at 02:24 PM.
  Reply With Quote
11-02-14, 08:16 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Xrystal View Post
I take it you debugged it and it highlights that it is passing true for mana in hunters for a split second somewhere during that port before realising it is not really mana ?
I would guess the answer to that is "no", and that this is what is causing the problem. The return values from informational functions are not always reliable during PLAYER_ENTERING_WORLD.

Originally Posted by Xrystal View Post
Although maybe it is best to check for the class and spec to decide on damager type rather than rely on the power source. Just a thought.
I would agree, though I recall when I was helping him write this the first time around he really didn't want to do that for some reason. I also notice that the current code will incorrectly classify feral druids as casters much of the time, as feral druids still have mana until they shift into cat form. Also, it will throw an error for characters level 10 or higher who haven't yet selected a spec (eg. players who have unlearned their spec in preparation for learning a different spec).

I'd also suggest using values for "playerRole" that more closely match the values from role-related API functions, so "TANK" instead of "Tank", "HEALER" instead of "Healer", "DAMAGER" instead of "Melee", and just add an extra "CASTER" value for casters. This way you can cut out half your if/then checks.

I would just do something like this:

Code:
local playerRole

local isCaster = {
     DRUID = { true }, -- Balance
     MAGE = { true, true, true }, -- all specs
     PRIEST = { nil, nil, true }, -- Shadow
     SHAMAN = { true }, -- Elemental
     WARLOCK = { true, true, true } -- all specs
}

function nData:UpdatePlayerRole()
	local spec = GetSpecialization()
	if not spec then
		playerRole = nil
		return
	end

	local specRole = GetSpecializationRole(spec)
	if specRole == "DAMAGER" then
		local _, class = UnitClass("player")
		if isCaster[class][spec] then
			playerRole = "CASTER"
			return
		end
	end

	playerRole = specRole
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
11-03-14, 10:42 AM   #4
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Xrystal View Post
I take it you debugged it and it highlights that it is passing true for mana in hunters for a split second somewhere during that port before realising it is not really mana ?
I have no idea on how to "debug" a add-on. I probably should not be doing any of this stuff beings I have no high school diploma nor a college education and no training in programming or LUA coding. I'm a forklift operator for Coca-Cola that is a gamer.

Originally Posted by Phanx View Post
I would agree, though I recall when I was helping him write this the first time around he really didn't want to do that for some reason. I also notice that the current code will incorrectly classify feral druids as casters much of the time, as feral druids still have mana until they shift into cat form. Also, it will throw an error for characters level 10 or higher who haven't yet selected a spec (eg. players who have unlearned their spec in preparation for learning a different spec).

I'd also suggest using values for "playerRole" that more closely match the values from role-related API functions, so "TANK" instead of "Tank", "HEALER" instead of "Healer", "DAMAGER" instead of "Melee", and just add an extra "CASTER" value for casters. This way you can cut out half your if/then checks.

I would just do something like this:

Code:
local playerRole

local isCaster = {
     DRUID = { true }, -- Balance
     MAGE = { true, true, true }, -- all specs
     PRIEST = { nil, nil, true }, -- Shadow
     SHAMAN = { true }, -- Elemental
     WARLOCK = { true, true, true } -- all specs
}

function nData:UpdatePlayerRole()
	local spec = GetSpecialization()
	if not spec then
		playerRole = nil
		return
	end

	local specRole = GetSpecializationRole(spec)
	if specRole == "DAMAGER" then
		local _, class = UnitClass("player")
		if isCaster[class][spec] then
			playerRole = "CASTER"
			return
		end
	end

	playerRole = specRole
end
I thank you for the above code.

I had to remove the:
Code:
local playerRole
with this it would not show any text.

Also I had to change the below to show all the classes or a error popped up when it went to look for "CASTER"
Lua Code:
  1. local isCaster = {
  2.     -- All Classes are needed as to not cause a error when the table is called.
  3.     -- SpecID - Spec - Role
  4.     DEATHKNIGHT = {
  5.         nil, -- 250 - Blood - (TANK)
  6.         nil, -- 251 - Frost - (MELEE_DPS)
  7.         nil  -- 252 - Unholy - (MELEE_DPS)
  8.     },
  9.     DRUID = {
  10.         true, -- 102 - Balance - (CASTER_DPS)
  11.         nil,  -- 103 - Feral - (MELEE_DPS)
  12.         nil,  -- 104 Guardian - (TANK)
  13.         nil   -- 105 Restoration - (HEALER)
  14.     },
  15.     HUNTER = {
  16.         nil, -- 253 - Beast Mastery - (RANGED_DPS)
  17.         nil, -- 254 - Marksmanship - (RANGED_DPS)
  18.         nil  -- 255 - Survival - (RANGED_DPS)
  19.     },
  20.     MAGE = {
  21.         true, -- 62 - Arcane - (CASTER_DPS)
  22.         true, -- 63 - Fire - (CASTER_DPS)
  23.         true  -- 64 - Frost - (CASTER_DPS)
  24.     },
  25.     MONK = {
  26.         nil, -- 268 - Brewmaster - (TANK)
  27.         nil, -- 269 - Windwalker - (MELEE_DPS)
  28.         nil  -- 270 - Mistweaver - (HEALER)
  29.     },
  30.     PALADIN = {
  31.         nil, -- 65 - Holy - (HEALER)
  32.         nil, -- 66 - Protection - (TANK)
  33.         nil  -- 70 - Retribution - (MELEE_DPS)
  34.     },
  35.     PRIEST = {
  36.         nil,  -- 256 - Discipline - (HEALER}
  37.         nil,  -- 257 - Holy - (HEALER)
  38.         true  -- 258 - Shadow - (CASTER_DPS)
  39.     },
  40.     ROGUE = {
  41.         nil, -- 259 - Assassination - (MELEE_DPS)
  42.         nil, -- 260 - Combat - (MELEE_DPS)
  43.         nil  -- 261 - Subtlety - (MELEE_DPS)
  44.     },
  45.     SHAMAN = {
  46.         true, -- 262 - Elemental - (CASTER_DPS)
  47.         nil,  -- 263 - Enhancement - (MELEE_DPS)
  48.         nil   -- 264 - Restoration - (HEALER)
  49.     },
  50.     WARLOCK = {
  51.         true, -- 265 - Affliction - (CASTER_DPS)
  52.         true, -- 266 - Demonology - (CASTER_DPS)
  53.         true  -- 267 - Destruction - (CASTER_DPS)
  54.     },
  55.     WARRIOR = {
  56.         nil, -- 71 - Arms - (MELEE_DPS)
  57.         nil, -- 72 - Furry - (MELEE_DPS)
  58.         nil  -- 73 - Protection - (TANK)
  59.     },
  60. }
I know its a little over the top but as you stated before Phanx its a file not a macro so be specific.

Here is the new Statisctics.lua file:
Lua Code:
  1. local nData = LibStub("AceAddon-3.0"):GetAddon("nData")
  2.  
  3. ------------------------------------------------------------------------
  4. --   Statistics Plugin Functions
  5. ------------------------------------------------------------------------
  6. nData.pluginConstructors["stat1"] = function()
  7.  
  8.     db = nData.db.profile
  9.    
  10.     local plugin = CreateFrame('Frame', nil, Datapanel)
  11.     plugin:RegisterEvent("PLAYER_ENTERING_WORLD")
  12.     plugin:SetFrameStrata("BACKGROUND")
  13.     plugin:SetFrameLevel(3)
  14.     plugin:EnableMouse(true)
  15.  
  16.     local Text  = plugin:CreateFontString(nil, "OVERLAY")
  17.     Text:SetFont(db.font, db.fontSize,'THINOUTLINE')
  18.     nData:PlacePlugin(db.stat1, Text)
  19.  
  20.     local playerClass, englishClass = UnitClass("player");
  21.  
  22.     local function ShowTooltip(self)
  23.         if InCombatLockdown() then return end
  24.    
  25.         local anchor, panel, xoff, yoff = nData:DataTextTooltipAnchor(Text)
  26.         GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  27.         GameTooltip:ClearLines()
  28.         GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Statistics")
  29.         GameTooltip:AddLine' '     
  30.         if playerRole == nil then
  31.             GameTooltip:AddLine("Choose a Specialization to see Stats")
  32.         else
  33.             if playerRole == "TANK" then
  34.                 local Total_Dodge = GetDodgeChance()
  35.                 local Total_Parry = GetParryChance()
  36.                 local Total_Block = GetBlockChance()
  37.                
  38.                 GameTooltip:AddLine(STAT_CATEGORY_DEFENSE)
  39.                 GameTooltip:AddDoubleLine(DODGE_CHANCE, format("%.2f%%", Total_Dodge),1,1,1)
  40.                 GameTooltip:AddDoubleLine(PARRY_CHANCE, format("%.2f%%", Total_Parry),1,1,1)
  41.                 GameTooltip:AddDoubleLine(BLOCK_CHANCE, format("%.2f%%", Total_Block),1,1,1)               
  42.                
  43.             elseif playerRole == "HEALER" or playerRole == "CASTER" then
  44.                 local SC = GetSpellCritChance("2")
  45.                 local Total_Spell_Haste = UnitSpellHaste("player")
  46.                 local base, casting = GetManaRegen()
  47.                 local manaRegenString = "%d / %d"              
  48.                
  49.                 GameTooltip:AddLine(STAT_CATEGORY_SPELL)
  50.                 GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", SC), 1, 1, 1)
  51.                 GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Spell_Haste), 1, 1, 1)    
  52.                 GameTooltip:AddDoubleLine(MANA_REGEN, format(manaRegenString, base * 5, casting * 5), 1, 1, 1)
  53.  
  54.             elseif playerRole == "DAMAGER" then        
  55.                 if englishClass == "HUNTER" then
  56.                     local Total_Range_Haste = GetRangedHaste("player")
  57.                     local Range_Armor_Pen = GetArmorPenetration();
  58.                     local Range_Crit = GetRangedCritChance("25")
  59.                     local speed = UnitRangedDamage("player")
  60.                     local Total_Range_Speed = speed
  61.                    
  62.                     GameTooltip:AddLine(STAT_CATEGORY_RANGED)                  
  63.                     GameTooltip:AddDoubleLine("Armor Penetration", format("%.2f%%", Range_Armor_Pen), 1, 1, 1)
  64.                     GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", Range_Crit), 1, 1, 1) 
  65.                     GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Range_Haste), 1, 1, 1)
  66.                     GameTooltip:AddDoubleLine(STAT_ATTACK_SPEED, format("%.2f".." (sec)", Total_Range_Speed), 1, 1, 1)                 
  67.                 else
  68.                     local Melee_Crit = GetCritChance("player")
  69.                     local Melee_Armor_Pen = GetArmorPenetration();
  70.                     local Total_Melee_Haste = GetMeleeHaste("player")
  71.                     local mainSpeed = UnitAttackSpeed("player");
  72.                     local MH = mainSpeed
  73.                    
  74.                     GameTooltip:AddLine(STAT_CATEGORY_MELEE)
  75.                     GameTooltip:AddDoubleLine("Armor Penetration", format("%.2f%%", Melee_Armor_Pen), 1, 1, 1)
  76.                     GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", Melee_Crit), 1, 1, 1)     
  77.                     GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Melee_Haste), 1, 1, 1)
  78.                     GameTooltip:AddDoubleLine(STAT_ATTACK_SPEED, format("%.2f".." (sec)", MH), 1, 1, 1)
  79.                 end
  80.             end
  81.             GameTooltip:AddLine' '
  82.             GameTooltip:AddLine(STAT_CATEGORY_GENERAL)
  83.             local masteryspell
  84.             local Multi_Strike = GetMultistrike();
  85.             local Life_Steal = GetLifesteal();
  86.             --local Versatility = GetVersatility();
  87.             local Versatility_Damage_Bonus = GetCombatRatingBonus(CR_VERSATILITY_DAMAGE_DONE) + GetVersatilityBonus(CR_VERSATILITY_DAMAGE_DONE);
  88.             local Avoidance = GetAvoidance();
  89.             local bonusArmor, isNegatedForSpec = UnitBonusArmor("player");
  90.            
  91.             GameTooltip:AddDoubleLine(STAT_BONUS_ARMOR, format("%s", bonusArmor), 1, 1, 1)
  92.             GameTooltip:AddDoubleLine(STAT_MULTISTRIKE, format("%.2f%%", Multi_Strike), 1, 1, 1)
  93.             GameTooltip:AddDoubleLine(STAT_LIFESTEAL, format("%.2f%%", Life_Steal), 1, 1, 1)
  94.             GameTooltip:AddDoubleLine(STAT_VERSATILITY, format("%.2f%%", Versatility_Damage_Bonus), 1, 1, 1)
  95.             --GameTooltip:AddDoubleLine(STAT_VERSATILITY, format("%d", Versatility), 1, 1, 1)
  96.             GameTooltip:AddDoubleLine(STAT_AVOIDANCE, format("%.2f%%", Avoidance), 1, 1, 1)
  97.             if GetCombatRating(CR_MASTERY) ~= 0 and GetSpecialization() then
  98.                 if englishClass == "DRUID" then
  99.                     if playerRole == "DAMAGER" and not playerRole == "CASTER" then
  100.                         masteryspell = select(2, GetSpecializationMasterySpells(GetSpecialization()))
  101.                     elseif playerRole == "TANK" then
  102.                         masteryspell = select(1, GetSpecializationMasterySpells(GetSpecialization()))
  103.                     else
  104.                         masteryspell = GetSpecializationMasterySpells(GetSpecialization())
  105.                     end
  106.                 else
  107.                     masteryspell = GetSpecializationMasterySpells(GetSpecialization())
  108.                 end
  109.                
  110.  
  111.                 local Mastery = GetMasteryEffect("player")
  112.                 local masteryName, _, _, _, _, _, _, _, _ = GetSpellInfo(masteryspell)
  113.                 if masteryName then
  114.                     GameTooltip:AddDoubleLine(masteryName, format("%.2f%%", Mastery), 1, 1, 1)
  115.                 end
  116.             end        
  117.         end
  118.  
  119.         GameTooltip:Show()
  120.     end
  121.  
  122.     local function UpdateTank(self)
  123.         local armorString = hexa..ARMOR..hexb..": "
  124.         local displayNumberString = string.join("", "%s", "%d|r");
  125.         local base, effectiveArmor, armor, posBuff, negBuff = UnitArmor("player");
  126.         local Melee_Reduction = effectiveArmor
  127.        
  128.         Text:SetFormattedText(displayNumberString, armorString, effectiveArmor)
  129.         --Setup Tooltip
  130.         self:SetAllPoints(Text)
  131.     end
  132.  
  133.     local function UpdateCaster(self)
  134.         local spellpwr = GetSpellBonusDamage("2");
  135.         local displayNumberString = string.join("", "%s", "%d|r");
  136.        
  137.         Text:SetFormattedText(displayNumberString, hexa.."SP: "..hexb, spellpwr)
  138.         --Setup Tooltip
  139.         self:SetAllPoints(Text)
  140.     end
  141.  
  142.     local function UpdateDamager(self) 
  143.         local displayNumberString = string.join("", "%s", "%d|r");
  144.            
  145.         if englishClass == "HUNTER" then
  146.             local base, posBuff, negBuff = UnitRangedAttackPower("player")
  147.             local Range_AP = base + posBuff + negBuff  
  148.             pwr = Range_AP
  149.         else
  150.             local base, posBuff, negBuff = UnitAttackPower("player")
  151.             local Melee_AP = base + posBuff + negBuff      
  152.             pwr = Melee_AP
  153.         end
  154.        
  155.         Text:SetFormattedText(displayNumberString, hexa.."AP: "..hexb, pwr)      
  156.         --Setup Tooltip
  157.         self:SetAllPoints(Text)
  158.     end
  159.  
  160.     -- initial delay for update (let the ui load)
  161.     local int = 5  
  162.     local function Update(self, t)
  163.         int = int - t
  164.         if int > 0 then return end
  165.         if playerRole == nil then
  166.             Text:SetText(hexa.."No Stats"..hexb)
  167.         else
  168.             if playerRole == "TANK" then
  169.                 UpdateTank(self)
  170.             elseif playerRole == "HEALER" or playerRole == "CASTER" then
  171.                 UpdateCaster(self)
  172.             elseif playerRole == "DAMAGER" then
  173.                 UpdateDamager(self)
  174.             end
  175.         end
  176.         int = 2
  177.     end
  178.  
  179.     plugin:SetScript("OnEnter", function() ShowTooltip(plugin) end)
  180.     plugin:SetScript("OnLeave", function() GameTooltip:Hide() end)
  181.     plugin:SetScript("OnUpdate", Update)
  182.     Update(plugin, 10)
  183.  
  184.     return plugin -- important!
  185. end

Thank You for all the help with the nData project.
Coke

Last edited by cokedrivers : 11-03-14 at 11:40 AM.
  Reply With Quote
11-03-14, 01:52 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by cokedrivers View Post
I have no idea on how to "debug" a add-on. I probably should not be doing any of this stuff beings I have no high school diploma nor a college education and no training in programming or LUA coding. I'm a forklift operator for Coca-Cola that is a gamer.
Just add print("FunctionName or EVENT_NAME", someVar, otherVar) lines throughout the code so you can see what functions are running and what values are being set. This way you can tell that a function isn't being run when it should be, or that some variable isn't getting the value you expected, and you can go fix those problems instead of just trying random stuff. Now you are debugging.

Originally Posted by cokedrivers View Post
Here is the new Statisctics.lua file:
That code is setting a global "playerRole" variable. Put "local playerRole" at the top of the file. It probably didn't work before because you were defining the variable too far down in the file. Remember, you need to define variables above any parts of the code where you read from or write to them.
__________________
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
11-03-14, 02:11 PM   #6
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Phanx View Post
That code is setting a global "playerRole" variable. Put "local playerRole" at the top of the file. It probably didn't work before because you were defining the variable too far down in the file. Remember, you need to define variables above any parts of the code where you read from or write to them.
So my function nData:UpdatePlayerRole() is in my main nData.lua file. When I add local playerRole to the top of my nData.lua file it will not pass the playerRole onto the plugins, do I need to move the function nData:UpdatePlayerRole() to a different function within the nData.lua right no in the OnEnable there is this code:
Code:
	-- no need to make a separate frame to handle events, your module object already does this!
	self:UpdatePlayerRole()
	self:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED", "UpdatePlayerRole")
Coke
  Reply With Quote
11-03-14, 05:05 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If you want it to work across different files, the simplest solution would be to add the "playerRole" value to your addon's object instead of having it a standalone variable.

Remove the line where you declare the variable in your main file:
Code:
local playerRole
Then, everywhere you look at or set "playerRole" in any file, change it to "nData.playerRole".
__________________
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
11-03-14, 06:08 PM   #8
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Phanx View Post
If you want it to work across different files, the simplest solution would be to add the "playerRole" value to your addon's object instead of having it a standalone variable.

Remove the line where you declare the variable in your main file:
Code:
local playerRole
Then, everywhere you look at or set "playerRole" in any file, change it to "nData.playerRole".
In order to not throw a error I had to change the main nData:UpdatePlayerRole() to this:
Code:
function nData:UpdatePlayerRole()	
	local spec = GetSpecialization()
	if not spec then
		self.playerRole = nil
		return
	end

	local specRole = GetSpecializationRole(spec)
	if specRole == "DAMAGER" then
		if isCaster[class][spec] then
			self.playerRole = "CASTER"
			return
		end
	end

	self.playerRole = specRole
end
had to add the "self." in front of playerRole to make it work.

Thanks for helping me on this.
Coke
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Stat Switching Unexpectedly


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