Posted: Sat Mar 06, 2021 4:33 am Post subject: Need help with lua timer toggle script
hi, i have two scripts, how do i make them switch to each other every 5 second?
like first 5 second the script 1 will be on, then next 5 second script 1 turn off and script 2 turn on, 5 second again script 1 turn on and script 2 turn off...
im sorry im newbie and dont know how to make it so i need some help
if ftimer then ftimer.destroy() ftimer=nil end
ftimer=createTimer()
ftimer.Interval=1000 ftimer.Enabled=false
local tIndx=0
local fIndx=1
ftimer.OnTimer=function()
tIndx=tonumber(tIndx) + 1
--print(tIndx)
if tIndx==5 then
if fIndx==1 then
print("function "..fIndx.." active") --your function 1
fIndx=2
tIndx=0
else
print("function "..fIndx.." active") --your function 2
fIndx=1
tIndx=0
end
end
end
Posted: Sat Mar 06, 2021 7:39 am Post subject: Re: Need help with lua timer toggle script
or other solution
Code:
if timer then timer.destroy() end -- if timer is exists then destroy it (so theres no duplicate timer)
timer = createTimer() -- create a timer
timer.interval = 5000 -- execute ontimer event every 5 seconds
timer.enabled = true -- start the timer
local switch = 0 -- a switch variable for specific script to be executed
timer.ontimer = function() -- ontimer event that execute every 5 sec
if switch == 0 then
switch = 1 -- if switch is 0 then it change to 1 and execute the first script
print("first script")
elseif switch == 1 then
switch = 0 -- if switch is 1 then it change to 0 and execute the second script
print("second script")
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum