Originally Posted by cokedrivers
so this is the code I use that hides or shows the Factions gold:
...
can it be condensed?
|
First, there should be no apostrophe in "Characters".
Oh, and your totalAllianceGold variable was misspelled, but at least it matched everywhere.
Second, you're getting the gaps because you're adding the gaps.
(Oh, and you also don't need to add a double-line to create a spacer, it can just be a regular line. This way you don't end up with more strings created in memory than necessary.)
Lua Code:
local totalGold = 0;
local totalAlianceGold = 0;
local totalHordeGold = 0;
local totalNeutralGold = 0;
if db['Gold'][myPlayerRealm]['Alliance'] == nil then
GameTooltip:AddDoubleLine(" ", " ") --no alliance characters, but let's add a line anyway
else
GameTooltip:AddLine("Alliance Character's:")
for k,v in pairs(db['Gold'][myPlayerRealm]['Alliance']) do
GameTooltip:AddDoubleLine(iconAlliance..k, formatMoney(v), 1, 1, 1, 1, 1, 1)
totalAlianceGold = totalAlianceGold + v;
end
GameTooltip:AddDoubleLine("Total Alliance Gold", formatMoney(totalAlianceGold))
end
GameTooltip:AddDoubleLine(" ", " ") --now let's add a spacer between factions
if db['Gold'][myPlayerRealm]['Horde'] == nil then
GameTooltip:AddDoubleLine(" ", " ") --no horde characters, but let's add a line anyway
else
GameTooltip:AddLine("Horde Character's:")
for k,v in pairs(db['Gold'][myPlayerRealm]['Horde']) do
GameTooltip:AddDoubleLine(iconHorde..k, formatMoney(v), 1, 1, 1, 1, 1, 1)
totalHordeGold = totalHordeGold + v;
end
GameTooltip:AddDoubleLine("Total Horde Gold", formatMoney(totalHordeGold))
end
GameTooltip:AddDoubleLine(" ", " ") --now let's add a spacer
if db['Gold'][myPlayerRealm]['Neutral'] == nil then
GameTooltip:AddDoubleLine(" ", " ")
else
GameTooltip:AddLine("Neutral Character's:")
for k,v in pairs(db['Gold'][myPlayerRealm]['Neutral']) do
GameTooltip:AddDoubleLine(iconNuetral..k, formatMoney(v), 1, 1, 1, 1, 1, 1)
totalNeutralGold = totalNeutralGold + v;
end
GameTooltip:AddDoubleLine("Total Neutral Gold", formatMoney(totalNeutralGold))
end
local totalServerGold = totalAlianceGold + totalHordeGold + totalNeutralGold
GameTooltip:AddLine" "
GameTooltip:AddDoubleLine("Total Gold for "..myPlayerRealm, formatMoney(totalServerGold))
For example, I've commented above how it is that you are getting 4 blank lines instead of one if you have only neutral characters on a server.
If you follow the logic of what you are trying to do, you want an empty line (a spacer) after every faction's section. This is even true for the last displayed faction in the tooltip, since you want a spacer before the total gold on the realm. If a faction's info will not be present in the tooltip, then you don't need the spacer. If you wish to keep your code formatted as is (rather than jlam's condensed version), then do this instead.
Lua Code:
local totalGold = 0
local totalAllianceGold = 0
local totalHordeGold = 0
local totalNeutralGold = 0
if db['Gold'][myPlayerRealm]['Alliance'] then --so long as this will never have a value of false, you really only care if a value exists
GameTooltip:AddLine("Alliance Characters:") --faction heading
for k,v in pairs(db['Gold'][myPlayerRealm]['Alliance']) do --display all characters
GameTooltip:AddDoubleLine(iconAlliance..k, formatMoney(v), 1, 1, 1, 1, 1, 1)
totalAllianceGold = totalAllianceGold + v
end
GameTooltip:AddDoubleLine("Total Alliance Gold", formatMoney(totalAllianceGold)) --faction total
GameTooltip:AddLine("") --add a spacer after this faction
end
if db['Gold'][myPlayerRealm]['Horde'] then
GameTooltip:AddLine("Horde Characters:") --faction heading
for k,v in pairs(db['Gold'][myPlayerRealm]['Horde']) do --display all characters
GameTooltip:AddDoubleLine(iconHorde..k, formatMoney(v), 1, 1, 1, 1, 1, 1)
totalHordeGold = totalHordeGold + v
end
GameTooltip:AddDoubleLine("Total Horde Gold", formatMoney(totalHordeGold)) --faction total
GameTooltip:AddLine("") --add a spacer after this faction
end
if db['Gold'][myPlayerRealm]['Neutral'] then
GameTooltip:AddLine("Neutral Characters:") --faction heading
for k,v in pairs(db['Gold'][myPlayerRealm]['Neutral']) do --display all characters
GameTooltip:AddDoubleLine(iconNuetral..k, formatMoney(v), 1, 1, 1, 1, 1, 1)
totalNeutralGold = totalNeutralGold + v
end
GameTooltip:AddDoubleLine("Total Neutral Gold", formatMoney(totalNeutralGold)) --faction total
GameTooltip:AddLine("") --add a spacer after this faction
end
local totalServerGold = totalAlianceGold + totalHordeGold + totalNeutralGold
GameTooltip:AddDoubleLine("Total Gold for "..myPlayerRealm, formatMoney(totalServerGold)) --server total