1. #1

    [lua] FontString help

    hey guys,

    working on some infopanels for my ui. so what i have is this
    Code:
    local MyAvoid = 5+GetParryChance("Player")+GetDodgeChance("Player")
    
    local MyAvoidance = CreateFrame("FRAME", nil, UIParent)
        MyAvoidance:SetPoint("CENTER", UIParent, 0, 0)
    	MyAvoidance:SetWidth(200)
        MyAvoidance:SetHeight(20)
        
        local MyAvoidanceText = MyAvoidance:CreateFontString()
            MyAvoidanceText:SetPoint("CENTER")
            MyAvoidanceText:SetSize(200, 20)
            MyAvoidanceText:SetFont(cfg.font, 12, "OUTLINE")
            MyAvoidanceText:SetText("Avoidance: "..MyAvoid.."%")
    my avoidance is shown correct but like 25.175693545672348%.
    how can i abbreviate the fontstring that it is shown as 25.1% or 25.17%

    thank you for helping me
    Last edited by Vyntrox; 2013-02-11 at 02:45 PM.

  2. #2
    Change
    Code:
    MyAvoidanceText:SetText("Avoidance: "..MyAvoid.."%")
    To
    Code:
    MyAvoidanceText:SetFormattedText("Avoidance: %.2f%%", MyAvoid)
    For 25.17%, or %.1f for 25.1%
    Author of BadBoy, BasicChatMods, BigWigs, oRA3, SexyMap, [...]

    DBM: 21.2 CPU/sec
    BW: 3.7 CPU/sec
    [Source]

  3. #3
    For 25.17%, or %.1f for 25.1%
    <nitpick>It would be 25.18% and 25.2%</nitpick>
    UI & AddOns expert | Interface & Macros moderator - My work

  4. #4
    For 25.17%, or %.1f for 25.1%
    <nitpick>It would be 25.18% and 25.2%</nitpick>
    ups! u r absolutely right treeston


    but what i forgot, now i have the avoidance displayed, but it's static.
    how do i have to setup the script to make it dynamic respectively wich event is fired.

    Code:
    MyAvoidance:RegisterEvent(...)
    
    MyAvoidance:SetScript("OnUpdate" , function(self) ... end)

  5. #5
    EDIT: Woops, glanced and thought you were working with health.
    Last edited by Woogs; 2013-02-11 at 08:09 PM.

  6. #6
    OnUpdate will fire on every redraw as long as your frame :IsVisible.
    You'll want OnEvent with COMBAT_RATING_UPDATE

    Here is how I'd do what you want:
    Code:
    local MyAvoidance = CreateFrame("FRAME", nil, UIParent)
    MyAvoidance:SetPoint("CENTER", UIParent, 0, 0)
    MyAvoidance:SetWidth(200)
    MyAvoidance:SetHeight(20)
        
    MyAvoidance.text = MyAvoidance:CreateFontString()
    MyAvoidance.text:SetPoint("CENTER")
    MyAvoidance.text:SetSize(200, 20)
    MyAvoidance.text:SetFont(cfg.font, 12, "OUTLINE")
    
    MyAvoidance:RegisterEvent("COMBAT_RATING_UPDATE")
    MyAvoidance:SetScript("OnEvent",function(self)
        self.text:SetFormattedText("Avoidance: %.2f%%",5+GetParryChance("Player")+GetDodgeChance("Player"))
    end)
    UI & AddOns expert | Interface & Macros moderator - My work

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •