Page 1 of 1

onTick

Posted: Wed Jul 29, 2015 4:53 am
by madjak
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

Posted: Wed Jul 29, 2015 6:50 am
by madjak
hmm it looks like Modulus (%) in Lua scripting doesn't work... any ideas?

Posted: Wed Jul 29, 2015 7:08 am
by madjak
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.