Quantcast
Lua Help for New Coder - WoWInterface
Thread Tools Display Modes
09-30-20, 08:58 PM   #1
ashpoker
A Defias Bandit
Join Date: Sep 2020
Posts: 2
Post Lua Help for New Coder

I am having issues having a list displayed in a frame with general character information, ie armor pen, dodge, parry, etc. I can have one thing show but I am unable to get the second item to show up. below is the current code. Any help would be great thanks.

Code:
-------------------------------------------------------
-- Main Addon Stuff --
-------------------------------------------------------

local AshStats = CreateFrame("frame", "AshStatsFrame")
	AshStats:SetBackdrop({
		bgFile="Interface\\DialogFrame\\UI-DialogBox-Background",
		edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border",
		tile=1, tileSize=32, edgeSize=32,
		insets={left=11, right=12, top=12, bottom=11}
})

AshStats:SetWidth(170)
AshStats:SetHeight(400)
AshStats:SetPoint("CENTER",UIParent)
AshStats:EnableMouse(true)
AshStats:SetMovable(true)
AshStats:RegisterForDrag("LeftButton")
AshStats:SetScript("OnDragStart", function(self) self:StartMoving() end)
AshStats:SetScript("OnDragStart", function(self) self:StartMoving() end)
AshStats:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
AshStats:SetFrameStrata("FULLSCREEN_DIALOG")



AshStats:RegisterEvent("PLAYER_ENTERING_WORLD");
local function eventHandler(self, event, ...)
--print("Hello World! Hello " .. event);
end
AshStats:SetScript("OnEvent", eventHandler);
--------------------------------------------------------------
--Framerate
--------------------------------------------------------

local fpsframe = CreateFrame("Frame", nil, AshStats)
	fpsframe:SetFrameStrata("BACKGROUND")
	fpsframe:SetWidth(50)
	fpsframe:SetHeight(30)
	fpsframe:SetPoint("TOPLEFT", AshStats, "TOPLEFT", 20, -30)
	fpsframe:Show()

	fpsframe:RegisterEvent("ZONE_CHANGED")
	fpsframe:RegisterEvent("ZONE_CHANGED_INDOORS")
	fpsframe:RegisterEvent("ZONE_CHANGED_NEW_AREA")

local fpsframeFS = fpsframe:CreateFontString("FontString","OVERLAY","GameTooltipText")

	fpsframeFS:SetPoint("TOPLEFT",fpsframe,"TOPLEFT",0,0)
	fpsframeFS:SetFont("Fonts\\FRIZQT__.TTF", 10, "THINOUTLINE")

local elapsed = 0

	fpsframe:SetScript("OnUpdate", function(self, e)
		elapsed = elapsed + e
			if elapsed >= 1 then
				fpsframeRefresh()
				elapsed = 0
			end
	end)

	fpsframe:SetScript("OnEvent", function()
		fpsframeFS:SetTextColor(1, 1, 1);
		fpsframeRefresh()
	end)

function fpsframeRefresh()
	local framerate = GetFramerate()
		fpsframeFS:SetFormattedText("Frame Rate - " .. "%.0f", framerate)
end
-----------------------------------------------------
local armframe = CreateFrame("Frame", nil, AshStats)
	armframe:SetFrameStrata("BACKGROUND")
	armframe:SetWidth(50)
	armframe:SetHeight(30)
	armframe:SetPoint("TOPLEFT", AshStats, "TOPLEFT", 20, -40)
	armframe:Show()

	armframe:RegisterEvent("ZONE_CHANGED")
	armframe:RegisterEvent("ZONE_CHANGED_INDOORS")
	armframe:RegisterEvent("ZONE_CHANGED_NEW_AREA")

local armframeFS = armframe:CreateFontString("FontString","OVERLAY","GameTooltipText")

	armframeFS:SetPoint("TOPLEFT",armframe,"TOPLEFT",0,0)
	armframeFS:SetFont("Fonts\\FRIZQT__.TTF", 10, "THINOUTLINE")

function armframeRefresh()
	local armorPen = GetArmorPenetration()
		--armframeFS:SetFormattedText("Armor Pen - " .. , armorPen)
	print armorPen
end
  Reply With Quote
10-01-20, 12:29 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,292
You can just have one frame that hosts several Fontstrings and updates them as required (OnEvent, OnUpdate, or both) eg:

Lua Code:
  1. local fpsCheck = 3 -- update ~3 seconds
  2.  
  3. local AshStats = CreateFrame("frame", "AshStatsFrame")
  4. AshStats:SetBackdrop({ bgFile="Interface\\DialogFrame\\UI-DialogBox-Background",
  5.     edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border",
  6.     tile=1, tileSize=32, edgeSize=32,
  7.     insets={left=11, right=12, top=12, bottom=11}
  8. })
  9.  
  10. AshStats:SetWidth(170)
  11. AshStats:SetHeight(400)
  12. AshStats:SetPoint("CENTER",UIParent)
  13. AshStats:EnableMouse(true)
  14. AshStats:SetMovable(true)
  15. AshStats:RegisterForDrag("LeftButton")
  16. AshStats:SetScript("OnDragStart", function(self) self:StartMoving() end)
  17. AshStats:SetScript("OnDragStart", function(self) self:StartMoving() end)
  18. AshStats:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
  19. AshStats:SetFrameStrata("FULLSCREEN_DIALOG")
  20. -- fps fontstring
  21. AshStats.fps = AshStats:CreateFontString("$parentFPS","OVERLAY","GameTooltipText")
  22. AshStats.fps:SetPoint("TOPLEFT", 10, -10)
  23. AshStats.fps:SetFont("Fonts\\FRIZQT__.TTF", 10, "THINOUTLINE")
  24. -- latence fontstring
  25. AshStats.lat = AshStats:CreateFontString("$parentLatency","OVERLAY","GameTooltipText")
  26. AshStats.lat:SetPoint("TOPLEFT", AshStats.fps, "BOTTOMLEFT", 0, 0)
  27. AshStats.lat:SetFont("Fonts\\FRIZQT__.TTF", 10, "THINOUTLINE")
  28. -- zone fontstring
  29. AshStats.zone = AshStats:CreateFontString("$parentZone","OVERLAY","GameTooltipText")
  30. AshStats.zone:SetPoint("TOPLEFT", AshStats.lat, "BOTTOMLEFT", 0, 0)
  31. AshStats.zone:SetFont("Fonts\\FRIZQT__.TTF", 10, "THINOUTLINE")
  32. -- other fontstring
  33. AshStats.arm = AshStats:CreateFontString("$parentArm","OVERLAY","GameTooltipText")
  34. AshStats.arm:SetPoint("TOPLEFT", AshStats.zone, "BOTTOMLEFT", 0, 0)
  35. AshStats.arm:SetFont("Fonts\\FRIZQT__.TTF", 10, "THINOUTLINE")
  36.  
  37. AshStats:RegisterEvent("PLAYER_ENTERING_WORLD");
  38. AshStats:RegisterEvent("ZONE_CHANGED")
  39. AshStats:RegisterEvent("ZONE_CHANGED_INDOORS")
  40. AshStats:RegisterEvent("ZONE_CHANGED_NEW_AREA")
  41. local function eventHandler(self, event, ...)
  42.     if event == "PLAYER_ENTERING_WORLD" then -- updates on entering world events only
  43.         self.arm:SetText("Some Stat or other")
  44.     end
  45.     -- everthing below updates on all events
  46. -- zone text
  47.     self.zone:SetText(GetMinimapZoneText())
  48.     local r, g, b = 1, 1, 1
  49.     local ZoneType = GetZonePVPInfo()
  50.     if ZoneType == "sanctuary" then
  51.         r, g, b = .41, .8, .94
  52.     elseif ZoneType == "friendly" then
  53.         r, g, b = .1, 1, .1
  54.     elseif ZoneType == "contested" then
  55.         r, g, b = 1, .7, 0
  56.     elseif ZoneType == "hostile" then
  57.         r, g, b = 1, .1, .1
  58.     elseif ZoneType == "arena" then
  59.         r, g, b = 1, .1, .1
  60.     else
  61.         r, g, b = 1, .82, 0
  62.     end
  63.     self.zone:SetTextColor(r, g, b)
  64. end
  65. AshStats:SetScript("OnEvent", eventHandler);
  66.  
  67. AshStats.elapsed = fpsCheck
  68. AshStats:SetScript("OnUpdate", function(self, elapsed)
  69.     self.elapsed = self.elapsed - elapsed -- Countdown to zero
  70.     if self.elapsed > 0 then return end
  71.     self.elapsed = fpsCheck -- and reset/start again
  72.  
  73. -- FPS
  74.     self.fps:SetText("Frame Rate - "..format("%0.i", GetFramerate()))
  75. -- Latency
  76.     local _,_,Latency = GetNetStats()
  77.     local r, g, b
  78.     if Latency > PERFORMANCEBAR_MEDIUM_LATENCY then -- 600
  79.         r, g, b = 1, 0, 0
  80.     elseif Latency > PERFORMANCEBAR_LOW_LATENCY then -- 300
  81.         r, g, b = 1, .82, 0
  82.     else
  83.         r, g, b = 0, 1, 0
  84.     end
  85.     self.lat:SetText(Latency.."ms")
  86.     self.lat:SetTextColor(r, g, b)
  87. end)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Lua Help for New Coder

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