I'm trying to run multiple functions at different tick rates... what is the best way to achieve this? Below I've written a script that will process functions based on a modulus.
TickCount = 0
function onTick() --25Hz
processCAN()
ShiftLights()
if TickCount % 10 == 0 then --2.5Hz
runGearCalc()
end
if TickCount % 25 == 0 then --1Hz
runLoggingScript()
runDebugScrip()
end
TickCount = TickCount + 1
end
onTick
here is my not-so-nice solution:
setTickRate(25)
TickArray = {0,0,0,0,0,0,0,0,0,1}
TickCount = 1
function onTick()
processCAN()
ShiftLights()
if (TickArray[TickCount] == 1 then
TickCount = 1
runLoggingScript()
runDebugScript()
end
TickCount = TickCount + 1
end
Basically processCAN and ShiftLights will run on 25Hz whilst the runLoggingScript and runDebugScript work ever 2.5Hz.
setTickRate(25)
TickArray = {0,0,0,0,0,0,0,0,0,1}
TickCount = 1
function onTick()
processCAN()
ShiftLights()
if (TickArray[TickCount] == 1 then
TickCount = 1
runLoggingScript()
runDebugScript()
end
TickCount = TickCount + 1
end
Basically processCAN and ShiftLights will run on 25Hz whilst the runLoggingScript and runDebugScript work ever 2.5Hz.