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

os.startTimer(5) Help please

Started by Xoandbit, 07 July 2012 - 04:56 PM
Xoandbit #1
Posted 07 July 2012 - 06:56 PM
Hello..


I am trying to make program like this http://i.imgur.com/Sc0HT.png

Maybe you can tell your ideas how to make this program…



My idea - I have array of timers, and i start them for 15 sec … If i get in this time rednet signal for device then device timer reset and device state true… If i dont get rednet signal for 15 sec then i change state to false…

And my problem is… I cant get timer id :P/>/>

I am saving timers in array laiki

My code who dont work


os.startTimer(0.1)
  while true do
	  local evt, arg = os.pullEvent()
	  term.setCursorPos(10,10)
	  if evt == "timer" then
		 ir=false		
			for i=1,n do
				if laiki[i]==arg then
					aktivs[i]="OFF"
					ir=true
					break
				end
		  
			end
		 if ir==false then
			break
		 end		
	  else
			break
	  end
end


Only this code dont work…

I think i get timer id in wrong way…



Sorry for my english…
Xoandbit #2
Posted 07 July 2012 - 07:00 PM
[NOT] Sorry - I find my proble… Timer is 15000 seconds long not 15 seconds long… Fail…


I changed to 5 sec… in the end…

All work when get rednet signal - it change state to ON

But it dont get id
I was giving out evt… I wanted to see if computer get some timer event… Computer get timer event… But… I think computer cant find timer id :P/>/> help please
Sariaz #3
Posted 24 September 2012 - 04:13 PM
every time u start a timer it would make a new one (from what i know) so it wouldn't ever match the one in the table but if u assign a variable to the timer then it u can compare its output with the table and if it machos then thats the timer u were looking for.
Fatal_Exception #4
Posted 24 September 2012 - 05:54 PM

local timerID = os.startTimer(1)

local event, arg1 = os.pullEvent()
if event == "timer" and arg1 == timerID then
  print("My timer fired!")
end