I'm trying to run multiple timers in a project. I call poll_timer(n) and I get a trigger when
n has elapsed. It works fine except where 2 scripts that use it have overlapping range. If I place the script at the bottom of each calling script it works fine and I've had 3 timers all running with different n values with no issue. An easy enough workround but inefficient, obviously.
In the tradition of a pedantic and perfectionist coder I know I can do better so quite some time was spent trying to get some kind of indexing array happening so I could call with poll_timer(index,n) but after 4 hours my eyes are glassed over and my head is done in.
I need a single function with multiple call ability with concurrent overlap.
How would you do it? I'm almost in quit mode and will settle for the workround
Can you help me Obiwan?
local tupdate = 0
local start_time=math.ceil(g_Time/1000)
function tt_timer_init(e)
end
function tt_timer_main(e)
end
function poll_timer(finish)
local stop_time=math.ceil(g_Time/1000)
local t_elapsed=start_time-stop_time
if t_elapsed == 0 then
tupdate=tupdate+1
PromptDuration("Timer working? (" .. tupdate..")",1000)
end
start_time=stop_time+1
if tupdate == finish then
tupdate = 0 -- reset for next use
return 1 -- pass on the good news
else
return 0 -- we're not done yet
end
end -- poll timer
edited typos
Development/ Gaming Rigs
Sys 1: i7-4770 (3.5)/16Gb/128 SSD/3Tb/970gtx/2 x 23, 1 x 27 LCD - Sys 2: i7/8Gb/670gtx/1.5Tb/1 x 23 LCD - Sys 3: Amd Quad/8Gb/645gtx/1Tb/30" LCD