WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   show decisecond when timer is at one second (https://www.wowinterface.com/forums/showthread.php?t=58802)

rulezyx 06-20-21 09:08 PM

show decisecond when timer is at one second
 
Hello,

usually I write something like %.1f instead of %d to get it to show one decimalpoint.

But I want to make it so that it only turns to decimalpoint when the timer is at one (1) second.

so 3, 2, 1 ,0.9, 0.8. 0.7 etc.

Is there a simple solution to make this happen?

Thank you.

kurapica.igas 06-21-21 12:23 AM

just string.format(val >= 1 and "%d" or "%.1f", val))

rulezyx 06-21-21 04:36 AM

ty:) will try to work with that

rulezyx 06-21-21 05:26 AM

Ok, I tried to find a code for the default buff/debuff frames to put it together.

Found this:

Code:

function AuraButton_UpdateDuration(auraButton, timeLeft)
        local duration = auraButton.duration;
        if ( SHOW_BUFF_DURATIONS == "1" and timeLeft ) then
                duration:SetFormattedText(SecondsToTimeAbbrev(timeLeft));
                if ( timeLeft < BUFF_DURATION_WARNING_TIME ) then
                        duration:SetVertexColor(1,1,1);
                else
                        duration:SetVertexColor(1,1,1);
                end
                duration:Show();
        else
                duration:Hide();
        end
end

I am unsure how to use string.format in this case.:confused:

Blizz-Code:https://github.com/tomrus88/Blizzard.../BuffFrame.lua

Xrystal 06-21-21 10:25 AM

I've inserted the suggested code where it is likely to do what you want. Give that a go. This link points out the similarities between SetFormattedText and string.format. https://wowpedia.fandom.com/wiki/API...tFormattedText

Quote:

Originally Posted by rulezyx (Post 339428)
Ok, I tried to find a code for the default buff/debuff frames to put it together.

Found this:

Code:

function AuraButton_UpdateDuration(auraButton, timeLeft)
        local duration = auraButton.duration;
        if ( SHOW_BUFF_DURATIONS == "1" and timeLeft ) then
                duration:SetFormattedText(SecondsToTimeAbbrev(timeLeft));

>>>> if (timeLeft < 1.0 ) then
>>>>    duration:SetFormattedTextstring("%.1f", timeLeft)
>>>> end

                if ( timeLeft < BUFF_DURATION_WARNING_TIME ) then
                        duration:SetVertexColor(1,1,1);
                else
                        duration:SetVertexColor(1,1,1);
                end
                duration:Show();
        else
                duration:Hide();
        end
end

I am unsure how to use string.format in this case.:confused:

Blizz-Code:https://github.com/tomrus88/Blizzard.../BuffFrame.lua


rulezyx 06-21-21 11:11 AM

Code:

function AuraButton_UpdateDuration(auraButton, timeLeft)
        local duration = auraButton.duration;
        if ( SHOW_BUFF_DURATIONS == "1" and timeLeft ) then
        duration:SetFormattedText(SecondsToTimeAbbrev(timeLeft));

        if (timeLeft < 1.0 ) then
duration:SetFormattedText("%.1f", timeLeft)
        end

        if ( timeLeft < BUFF_DURATION_WARNING_TIME ) then
                duration:SetVertexColor(1,1,1);
        else
                duration:SetVertexColor(1,1,1);
        end
                duration:Show();
        else
                duration:Hide();
        end
end

seems to work fine.

Thank you :)


All times are GMT -6. The time now is 12:52 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI