Thread Tools Display Modes
06-20-21, 09:08 PM   #1
rulezyx
A Flamescale Wyrmkin
 
rulezyx's Avatar
Join Date: Jan 2020
Posts: 106
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.
  Reply With Quote
06-21-21, 12:23 AM   #2
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
just string.format(val >= 1 and "%d" or "%.1f", val))
  Reply With Quote
06-21-21, 04:36 AM   #3
rulezyx
A Flamescale Wyrmkin
 
rulezyx's Avatar
Join Date: Jan 2020
Posts: 106
ty will try to work with that
  Reply With Quote
06-21-21, 05:26 AM   #4
rulezyx
A Flamescale Wyrmkin
 
rulezyx's Avatar
Join Date: Jan 2020
Posts: 106
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.

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

Last edited by rulezyx : 06-21-21 at 05:58 AM.
  Reply With Quote
06-21-21, 10:25 AM   #5
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
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

Originally Posted by rulezyx View Post
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.

Blizz-Code:https://github.com/tomrus88/Blizzard.../BuffFrame.lua
__________________
  Reply With Quote
06-21-21, 11:11 AM   #6
rulezyx
A Flamescale Wyrmkin
 
rulezyx's Avatar
Join Date: Jan 2020
Posts: 106
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

Last edited by rulezyx : 06-21-21 at 11:16 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » show decisecond when timer is at one second

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