View Single Post
06-17-16, 09:22 PM   #6
Dejablue
A Wyrmkin Dreamwalker
 
Dejablue's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 58
Originally Posted by Lombra View Post
I would definitely use the manually created table instead. That's more reliable.

You're just missing a reference to your font strings. When you make the global reference the variable will just be overwritten and refer to whatever you assigned to it last, as you've noticed. What you should do is make a reference on the frames themselves.

Do this when creating the frames:
Code:
for k, v in ipairs(DCSITEM_SLOT_FRAMES) do
	local duraFS = v:CreateFontString("FontString","OVERLAY","GameTooltipText")
	duraFS:SetPoint("BOTTOM",v,"BOTTOM",0,0);
	duraFS:SetFont("Fonts\\FRIZQT__.TTF", 14, "THINOUTLINE");
	duraFS:SetFormattedText("lollolol");
	v.durability = duraFS
end
You may now access the font string through the durability field of each frame.

Code:
local function duraRefresh()
	for k, v in ipairs(DCSITEM_SLOT_FRAMES) do
		local slotId = v:GetID();
		-- print(slotId)
		local durCur, durMax = GetInventoryItemDurability(slotId)
		if durCur == nil or durMax == nil then
			v.durability:SetFormattedText("");
		elseif ( durCur ~= durMax ) then
			v.durability:SetFormattedText("%.0f%%", durCur*(100/durMax));
		end
	end
end
Yea I figured that out late last night but was just too tired to think of a solution, like how do I reference the frame itself with each iteration.

Thank you so much. I am very new to programming in general let alone lua.

Thanks for deciphering my spaghetti too and taking out the time. I will work on this over the weekend and post results or questions. Not that I expect you or anyone to continue to respond, but for other authors so that if they have this issue they can see what was done here. Archived posts has been a huge help to me.

Thanks again.

Cheers!
  Reply With Quote