This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
DTM450's profile picture

I'm having trouble restarting a timer loop (1.7.10)

Started by DTM450, 26 April 2016 - 01:26 AM
DTM450 #1
Posted 26 April 2016 - 03:26 AM
I'm trying to get this timer loop to work but it wont restart the timer when the loop restarts, I've tried putting myTimer in the loop but it doesnt start the timer at all then.


*snip*
local myTimer = os.startTimer(6)
while true do
  local event, par1 = os.pullEvent()
	if event == "timer" and par1 == myTimer then
	  if rs.getAnalogInput('front') < 14 then
	  Send()
	  end
	else if event == "redstone" then
	end
  end
end
Bomb Bloke #2
Posted 26 April 2016 - 03:34 AM
You need to start the timer before the loop starts, and then restart it every time you catch the relevant event.

*snip*
local myTimer = os.startTimer(6)
while true do
  local event, par1 = os.pullEvent()
        if event == "timer" and par1 == myTimer then
          if rs.getAnalogInput('front') < 14 then
          Send()
          end

          myTimer = os.startTimer(6)

        else if event == "redstone" then
        end
  end
end
DTM450 #3
Posted 26 April 2016 - 03:46 AM
ok sweet I got it working thanks