Uncle
Warcraft Moderator
- Joined
- Aug 10, 2018
- Messages
- 7,866
The problem is that the Reals aren't precise. Here's a simple code I made in Lua:
When I print out duration it starts out precise displaying "Duration = 5.00, 4.95, 4.90, etc..." but eventually it starts to lose precision and I begin to see "Duration = 3.999" instead of "Duration = 4.0". This is a problem if say I wanted to check when duration was equal to exactly "0.50". So how exactly would you recommend working around this?
I know I can rely on Integers like in the example above but I'd rather not do this since it complicates things (especially if I want the duration to change depending on different variables).
Am I missing something? Can I get precise Reals or am I stuck with using <= and booleans and all sorts of weird tricks to check how much time has elapsed in my repeating timer?
Lua:
local duration = 5.00
TimerStart(SomeTimer, 0.05, true, function()
duration = duration - 0.05
print("Duration = ", duration)
if duration <= 0 then
--End the timer
end
end
end)
Lua:
local counter = 100
TimerStart(SomeTimer, 0.05, true, function()
counter = counter - 1
print("Duration = ", counter)
if counter == 0 then
--End the timer
end
end
end)
Am I missing something? Can I get precise Reals or am I stuck with using <= and booleans and all sorts of weird tricks to check how much time has elapsed in my repeating timer?
Last edited: