Lua help UnitDebuff
I'm trying to calculate the time remaining for a specific debuff. I'm not getting any errors but I think my lack of lua Math and Rounding is causing a nonsensical return.
Given: Code:
local function getSpellTime(spell) Any idea what I need to get whole second times? |
So I realized part of my problem was having a narrow frame to display the value. I solved that part so it is now working except for the zillion decimal places showing up. How do I just drop the decimal values?
|
If you want to round up the value you can use math.ceil, or to round down the value you can use math.floor (http://lua-users.org/wiki/MathLibraryTutorial).
If you want to print a formatted value, but retain the actual value in the parameter, you can use string.format (http://www.lua.org/pil/20.html). |
Or something like:
Code:
FontString:SetFormattedText("%.0f", floor(timeleft)) |
Quote:
What does %.0f mean in english? |
Also, to clarify I don't want to round at all I just want to drop the decimal place.
From: 20.34546825638 To: 20 From: 20.67483 To: 20 |
Quote:
You can try it ingame with Code:
/dump string.format("%.0f", 24.1241) Code:
Dump: value=string.format("%.0f", 24.1241) |
Cool I'll try that tonight. While I was doing research on this I found some printf resources that said "%d" would give me the same results. Would that work in Lua too?
|
It would, but then it doesn't round the value.
With %.0f 21.7 becomes 22. With %d 21.7 becomes 21. |
Place holder for when I get home:
Code:
local function getSpellTime(spell) |
You can try
Code:
local function getSpellTime(spell) |
In my mod I use
Code:
function PallyPower:FormatTime(time) |
All times are GMT -6. The time now is 07:08 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI