[Lua] Need help with my addon code

Hey everyone,

I’m writing an addon and I’m trying to get the Spell cost of different spells in the spellbook. I’m aware that GetSpellPowerCost(“spellName” or spellID) is a thing. However my issue is when I try to pull the spell power cost from the spells in my spellbook and then display them in a tooltip. The problem that arises is that when I try to display them in a tooltip with the spellpower cost from GetSpellPowerCost it doesn’t even display the GameTooltip even when I call GameTooltip:Show()

Note: ‘SpellInfoTooltip’ is a GameTooltip described in an xml file with parent set to UIParent name being SpellInfoTooltip and inheriting from GameTooltipTemplate. I have a OnLoad script in the XML file that sets the Owner to ‘WorldFrame’.

I’m fairly new to Lua so go easy, but here’s my code for reference, and thanks for taking the time to read this:

local t = {[0] = "Mana", [1] = "Rage", [2] = "Focus", [3] = "Energy", [4] = "Happiness", [5] = "Runes", [6] = "Runic Power", [7] = "Soul Shards", [8] = "Eclipse", [9] = "Holy Power"};

SpellInfoTooltip:AddLine("Spells")

local i = 1;
while true do
	local spellName, spellSubName = GetSpellBookItemName(i, BOOKTYPE_SPELL)
	local spellID = select(2, GetSpellBookItemInfo(i, BOOKTYPE_SPELL))
	local usable = IsUsableSpell(spellID)
	local cost = 0
	local costTable = GetSpellPowerCost(spellID)
	for key, costInfo in pairs(costTable) do
		cost = costInfo.cost
		break
	end
	
	DEFAULT_CHAT_FRAME:AddMessage('Spell Cost: ' .. cost)
	
	if not spellName then
		do break end
	end
	
	if usable then
		if spellSubName == '' then
			SpellInfoTooltip:AddLine(spellName .. ', Cost: ' .. t[UnitPowerType("player")] .. ' Remaining: ' .. UnitPower("player") .. '/' .. UnitPowerMax("player") .. '; SpellID: ' .. spellID, 0,255,0)
		else 
			SpellInfoTooltip:AddLine(spellName .. ' (' .. spellSubName .. '), Cost: ' .. t[UnitPowerType("player")] .. ' Remaining: ' .. UnitPower("player") .. '/' .. UnitPowerMax("player") .. '; SpellID: ' .. spellID, 0,255,0)
		end
	else
		if spellSubName == '' then
			SpellInfoTooltip:AddLine(spellName .. ', Cost: ' .. t[UnitPowerType("player")] .. ' Remaining: ' .. UnitPower("player") .. '/' .. UnitPowerMax("player") .. '; SpellID: ' .. spellID, 255,0,0)
		else 
			SpellInfoTooltip:AddLine(spellName .. ' (' .. spellSubName .. '), Cost: ' .. t[UnitPowerType("player")] .. ' Remaining: ' .. UnitPower("player") .. '/' .. UnitPowerMax("player") .. '; SpellID: ' .. spellID, 255,0,0)
		end
	end
	
	i = i + 1
end

SpellInfoTooltip:SetBackdropColor(0,0,0,0.75)
SpellInfoTooltip:Show()