Beginner LF help - WoWInterface
Thread Tools Display Modes
10-06-19, 09:17 AM   #1
A Defias Bandit
Join Date: Oct 2019
Posts: 1
Beginner LF help

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).

	_G["HealthFrame_party"..i] = CreateFrame("Frame", "HBar_party"..i, UIParent)
	local HP_something = _G["Health_TEXT_" .. i];
	_G["HealthFrameText_party"..i] = HP_something:CreateFontString("Health_TEXT_party"..i, "OVERLAY", "TextStatusBarText")

	_G["Health_TEXT_party"..i]:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
	_G["HealthFrameText_party"..i]:SetPoint("CENTER", "PartyMemberFrame"..i , "CENTER", 20, 10);
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["f"..i..m]:SetSize(16, 16) 

		_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?

Im very thankful for any advice!
Attached Files
File Type: lua SimpleHealth.lua (5.8 KB, 48 views)
File Type: lua SimpleHealthUI.lua (4.7 KB, 43 views)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Beginner LF help

Thread Tools
Display Modes

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