UPDATE: My issue has been resolved.
Good afternoon everyone,
BLUF:
Code is not allowing proper mirroring of Quest Reward Value displayed in two separate panels.
I am looking for assistance in identifying a frustrating code complication that I can’t seem to fix and ChatGPT can’t seem to fix either.
The intent for this code is to display accurately the quest reward value in the quest log (next to quest titles), AND in the information panel attached to the Quest Reward Title Panel.
For reference, I am using Visual Studio Code
Below is the code I have so far, and would love for any insight on adjustment to reflect both values correctly and accurately:
– Basic Addon Setup
local QuestXPAddon = CreateFrame(“Frame”, “QuestXPAddonFrame”, UIParent)
– Register Events
QuestXPAddon:RegisterEvent(“ADDON_LOADED”)
QuestXPAddon:RegisterEvent(“QUEST_LOG_UPDATE”)
QuestXPAddon:RegisterEvent(“QUEST_DETAIL”)
– Function to Retrieve Adjusted XP from Quest Log Titles
local function GetAdjustedXPForQuest(questIndex)
local titleButton = _G[“QuestLogTitle” … questIndex]
if titleButton and titleButton.xpText then
local xpText = titleButton.xpText:GetText()
if xpText then
local xpValue = tonumber(xpText:match(“%d+”)) – Extract XP number from “XP: 1400”
return xpValue or 0
end
end
return 0 – Default to 0 if no XP is found
end
– Function to Display XP Reward Next to QuestLogRewardTitleText
local function DisplayXPNextToRewardTitle()
local questIndex = GetQuestLogSelection()
local adjustedXP = GetAdjustedXPForQuest(questIndex)
if not QuestLogRewardTitleText then
print("QuestLogRewardTitleText frame not found!") -- Debug message
return
end
if adjustedXP > 0 then
if not QuestLogFrame.XPRewardText then
-- Attach font string to QuestLogFrame and align relative to QuestLogRewardTitleText
local xpText = QuestLogFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
xpText:SetPoint("LEFT", QuestLogRewardTitleText, "RIGHT", -80, 0) -- Adjust position
xpText:SetTextColor(0.0, 0.8, 1.0)
QuestLogFrame.XPRewardText = xpText
end
-- Update and show the XP reward text
QuestLogFrame.XPRewardText:SetText("XP: " .. adjustedXP)
QuestLogFrame.XPRewardText:Show()
elseif QuestLogFrame.XPRewardText then
-- Hide the XP text if no reward is available
QuestLogFrame.XPRewardText:Hide()
end
end
– Handle XP Display in Quest Titles
local function HandleXPInQuestTitles()
local numEntries = GetNumQuestLogEntries()
for questIndex = 1, numEntries do
local title, level, _, isComplete, _, _, _, questID = GetQuestLogTitle(questIndex)
local questButton = _G["QuestLogTitle" .. questIndex]
-- Clear any existing XP text to prevent residual display issues
if questButton and questButton.xpText then
questButton.xpText:SetText("") -- Clear text
questButton.xpText:Hide() -- Hide XP display
end
-- Check if this is a quest
if questID > 0 and level > 0 then
SelectQuestLogEntry(questIndex) -- Ensure quest data is loaded
local xpReward = GetQuestLogRewardXP()
if isComplete then
-- Skip adding XP to the title for completed quests
if questButton and questButton.xpText then
questButton.xpText:Hide()
end
else
if xpReward > 0 then
-- Add XP display for incomplete quests
if questButton then
if not questButton.xpText then
-- Create a font string for XP display
local xpText = questButton:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
xpText:SetPoint("RIGHT", questButton, "RIGHT", -10, 0) -- Adjust position
xpText:SetTextColor(0.0, 0.8, 1.0)
questButton.xpText = xpText
end
-- Update XP text
questButton.xpText:SetText("XP: " .. xpReward)
questButton.xpText:Show()
end
end
end
end
end
end
– Event Handler
QuestXPAddon:SetScript(“OnEvent”, function(self, event, …)
if event == “ADDON_LOADED” and … == “QuestXPAddon” then
print(“QuestXPAddon loaded! XP rewards will now be displayed.”)
elseif event == “QUEST_LOG_UPDATE” then
HandleXPInQuestTitles()
elseif event == “QUEST_DETAIL” then
DisplayXPNextToRewardTitle()
end
end)
Thank you so much in advance.