Hey im at the very begining when it comes to lua and addons overall. However I did quite enjoy my recent attempts to create my own addons in Classic, but some questions popped in my head and I cant find answers on my own. I would be very happy if someone could help answer any (or all ) of these
My first addon attempt was to show HP&mana text on target and party frames. Its working fine more or less besides this part of code (which I had to replace for manualy written partyframes 1-4).
I always get error saying that HP_fontstring is nil value. I tried to test it and print out the HP_fontstring values before line 3 and it says that its nil aswell. Which is very strange to me because I used exactly this (just different variable names) in other part of code and it worked fine?
local HP_fontstring = _G["Health_TEXT_" .. unitToken];
HP_fontstring:SetFormattedText("%0.f%%", HealthPercent * 100)
these two lines (which were adviced to me by some helpful folk on addon discord) worked fine, but when I tried to re-use it it just didnt work The code is attached below.
Next question is regarding to the _G["string"]. After I used it about 100x times, I gained understanding that it changes string to global variable. Is that correct? In general, should I avoid using too many global variables when making an addon? Would adding local before declaring them help?
Next question is about CreateFontString() and SetFont(). Is there a function that would combine these two lines together? i wanted to use font FRIZQT__.TTF", 10, "OUTLINE" So I checked all the game fonts that looks the same and from which my CreateFontString() could inherit from, but I couldnt find one. It either was wrong size, outline or different colour than I wanted.
My second (current) addon attemp is to permanently show buffs on party member frames. While I got the main part somewhat working (time will show). I havent figured out any other way to do this than making 4*16 frames for each buff slot on each party member, which is probably wasteful approach to do it?
for m = 1, 4 do
for i = 1, 16 do
_G["f"..i..m] = CreateFrame("Frame", nil ,UIParent)
_G["t"..i..m] = _G["f"..i]:CreateTexture(nil,"ARTWORK")
_G["t"..i..m].texture = _G["t"..i]
_G["f"..i..m]:SetPoint("BOTTOMRIGHT", "PartyMemberFrame" .. m, "BOTTOMRIGHT", (i*16), 0);
So my question is, what would be the suitable way to handle this thing, and also is it possible to "uncreate" frames? Is using too many CreateFrame() unefficient/bad?