Jump to content




os.startTimer(5) Help please


  • You cannot reply to this topic
3 replies to this topic

#1 Xoandbit

  • Members
  • 5 posts

Posted 07 July 2012 - 05: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...

#2 Xoandbit

  • Members
  • 5 posts

Posted 07 July 2012 - 06: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

#3 Sariaz

  • Members
  • 107 posts

Posted 24 September 2012 - 03: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.

#4 Fatal_Exception

  • New Members
  • 105 posts

Posted 24 September 2012 - 04:54 PM

local timerID = os.startTimer(1)

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






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users