Thread Tools Display Modes
09-15-16, 10:51 AM   #1
Wolfenstein
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 2
Text in fram sometimes show wrong text

Hi everyone. I am pretty new to coding wow addons.

I have written this to keep track of a fire mages fireball crit chance.

Code:
FirelordFrame = CreateFrame("Frame", "FirelordFrame", UIParent)
FirelordFrame:RegisterEvent("UNIT_AURA")

function FirelordFrame_OnEvent(self, event, ...)
    local frame = self.frame
    if not frame then
	frame = CreateFrame('Frame', nil, UIParent, 'TimeToDieFrameTemplate')
        frame:EnableMouse(false)
        frame.bg:Hide()
        frame:SetWidth(128)
        frame:SetHeight(128)
        frame:SetPoint("CENTER",-32,0)
        frame.text = frame:CreateFontString(nil, "OVERLAY") --Create a FontString to display text
        frame.text:SetFont("Fonts\\FRIZQT__.TTF", 32, "THICKOUTLINE " )
        frame.text:SetTextColor(1, .75, 0)
        frame.text:SetAllPoints()
        frame.text:SetText("")
        frame.text:Show()
        frame:Show()
	self.frame = frame
	end
    local name, rank, icon, count = UnitBuff("player","Enhanced Pyrotechnics")
    if name
    then
        chanse = GetCombatRatingBonus(CR_CRIT_SPELL)
        ballCrit = (25 + chanse)*1.1 + 10*count
        intCrit = math.floor(ballCrit)
        DEFAULT_CHAT_FRAME:AddMessage("ballCrit = " .. intCrit)
        frame.text:SetText(intCrit)
    else
        frame.text:SetText("")
    end
end

FirelordFrame:SetScript("OnEvent",FirelordFrame_OnEvent)
The message in chat is always what I want it to be but the visible frame sometimes show the wrong number and I cannot figure out why.

The first image show a screen shoot of what I want and how it works most of the time.


But sometimes it looks like this.


What confuses me the most is that the number are obviously right because the chat message always show the number it should. Only the graphic on the screen gets it wrong.
  Reply With Quote
09-15-16, 12:28 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,882
You've got some unnecessary globals.

Lua Code:
  1. local FirelordFrame = CreateFrame("Frame", "FirelordFrame", UIParent)
  2. FirelordFrame:SetWidth(128)
  3. FirelordFrame:SetHeight(128)
  4. FirelordFrame:SetPoint("CENTER",-32,0)
  5. FirelordFrame.text = FirelordFrame:CreateFontString(nil, "OVERLAY") --Create a FontString to display text
  6. FirelordFrame.text:SetFont("Fonts\\FRIZQT__.TTF", 32, "THICKOUTLINE " )
  7. FirelordFrame.text:SetTextColor(1, .75, 0)
  8. FirelordFrame.text:SetAllPoints()
  9. FirelordFrame:RegisterEvent("UNIT_AURA")
  10.  
  11. local function FirelordFrame_OnEvent(self, event, ...)
  12.     local name, rank, icon, count = UnitBuff("player","Enhanced Pyrotechnics")
  13.     if not name then
  14.         self.text:SetText("")
  15.         return
  16.     end
  17.     local chanse = GetCombatRatingBonus(CR_CRIT_SPELL)
  18.     local ballCrit = (25 + chanse)*1.1 + 10*count
  19.     local intCrit = math.floor(ballCrit)
  20.     DEFAULT_CHAT_FRAME:AddMessage("ballCrit = " .. intCrit)
  21.     self.text:SetText(intCrit)
  22. end
  23.  
  24. FirelordFrame:SetScript("OnEvent", FirelordFrame_OnEvent)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-15-16 at 12:34 PM.
  Reply With Quote
09-15-16, 02:00 PM   #3
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
That makes no sense, but maybe try this:
Code:
frame.text:SetText(tostring(intCrit))
__________________
Grab your sword and fight the Horde!
  Reply With Quote
09-15-16, 04:04 PM   #4
Wolfenstein
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 2
Originally Posted by Fizzlemizz View Post
You've got some unnecessary globals.

Lua Code:
  1. local FirelordFrame = CreateFrame("Frame", "FirelordFrame", UIParent)
  2. FirelordFrame:SetWidth(128)
  3. FirelordFrame:SetHeight(128)
  4. FirelordFrame:SetPoint("CENTER",-32,0)
  5. FirelordFrame.text = FirelordFrame:CreateFontString(nil, "OVERLAY") --Create a FontString to display text
  6. FirelordFrame.text:SetFont("Fonts\\FRIZQT__.TTF", 32, "THICKOUTLINE " )
  7. FirelordFrame.text:SetTextColor(1, .75, 0)
  8. FirelordFrame.text:SetAllPoints()
  9. FirelordFrame:RegisterEvent("UNIT_AURA")
  10.  
  11. local function FirelordFrame_OnEvent(self, event, ...)
  12.     local name, rank, icon, count = UnitBuff("player","Enhanced Pyrotechnics")
  13.     if not name then
  14.         self.text:SetText("")
  15.         return
  16.     end
  17.     local chanse = GetCombatRatingBonus(CR_CRIT_SPELL)
  18.     local ballCrit = (25 + chanse)*1.1 + 10*count
  19.     local intCrit = math.floor(ballCrit)
  20.     DEFAULT_CHAT_FRAME:AddMessage("ballCrit = " .. intCrit)
  21.     self.text:SetText(intCrit)
  22. end
  23.  
  24. FirelordFrame:SetScript("OnEvent", FirelordFrame_OnEvent)
That fixed the problem but I am still confused as to why the error happened. It worked most of the time. It only got it an occasional flicker.
  Reply With Quote
09-15-16, 04:14 PM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,882
Possibly a second use of your original global FirelordFrame.frame.text by another addon. Just a guess but it was the first thing I thought possible when I read the code.

EDIT: Also possible:
Your global intCrit variable was "occasionaly" being updated by another addon between:
Code:
DEFAULT_CHAT_FRAME:AddMessage("ballCrit = " .. intCrit)
and
Code:
frame.text:SetText(intCrit)
Just because two lines of code appear one after another in your addon doesn't mean your computer doesn't execute other code (say from another addon) between them (or even different parts of each lines execution). It's also good reason to make sure ALL global variable names you use are unique to your addon.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-17-16 at 01:52 AM.
  Reply With Quote
09-16-16, 01:54 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Fizzlemizz View Post
It's also good reason to make sure ALL global variable names you use are unique to your addon.
And an even better reason to make sure you don't set any global variables unless it's actually necessary.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Text in fram sometimes show wrong text


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