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

Zeitschaltung:24: Attempt To Compare __Lt On Nil And Number

Started by BKamorC, 25 July 2013 - 10:55 AM
BKamorC #1
Posted 25 July 2013 - 12:55 PM
Hey Guys, I need some help with my program here

-- CC programmierbarer Timer/Zeitschaltuhr/Nachtlicht by BKamorC 25/07/2013
-- HINWEIS!! Zeitspannen, welche ?ber Mitternacht (Ingame) hinaus gehen, m?ssen
-- geteilt angegebne werden zB. 19:00 bis 6:15 wird dann so geschrieben:
-- zeiten[1] = {1900,2359}
-- zeiten[2] = {0000,0615}
local lout	 = ("right")  --Steuerausgang / Output
local onoff	= ("top")   --Aus-Aus Schalter
local refresh  = 0.8	   --Time to Refresh (100ms-800ms; 0.1 = fastest, 0.8 = slower)
zeiten = {}
	   zeiten[1] = {1900,2359}
	   zeiten[2] = {0000,0600}
	  
	  
	  
	  
	  
------------------------------------------------------------------------------------

local varfill = 0
function _fill(varfill)				 -- "9" -> "09"
		 if varfill < 10 then varfill = "0" ..varfill end
	return varfill
end
function _ftime()
   nHour	= math.floor(os.time())
   nMinute  = math.floor((os.time() -nHour)*60)
   stime	= _fill(nHour) .._filll(nMinute)
  return stime
end
function _akttime()
		 pzeit = os.time()
		 pzeit = textutils.formatTime(pzeit, true)
	return pzeit
end
function _testtime(zeiten,lout,onoff,refresh)
		 for i = 1, #zeiten, 1 do
			 lstart = zeiten[i][1]
			 lstop  = zeiten[i][2]
			 while tonumber(_ftime()) >= lstart and tonumber(_ftime()) <=lstop do
				   shell.run("clear")
				   print(_akttime().." | "..lstart.." : "..lstop)
				   if rs.getInput(onoff) == false then
					  rs.setOutput(lout, true)
				   else
					  rs.setOutput(lout, false)
				   end
				   sleep(refresh)
			 end
			 rs.setOutput(lout, false)
		 end
end
while true do
	  shell.run("clear")
	  print("aktuelle Zeit: ".._akttime())
	  _testtime(zeiten,lout,onoff,refresh)
	  sleep(refresh)
end

If possible and if you want, correct all my errors please
Thanks
Lyqyd #2
Posted 25 July 2013 - 01:59 PM
Split into new topic.
MR_nesquick #3
Posted 25 July 2013 - 02:17 PM

function _ftime()
   nHour	= math.floor(os.time())
   nMinute  = nHour*60
   stime	= nHour..nMinute
  return stime
end
———————

edit: are you trying to send a redstone pulse when it's night time?
Apfeldstrudel #4
Posted 25 July 2013 - 06:05 PM
Its all in german and there is no specific problem?
BKamorC #5
Posted 26 July 2013 - 04:12 AM
Yeah [member='MR_nesquick'] :)/>
MR_nesquick #6
Posted 26 July 2013 - 12:29 PM
starter code!. it will pulse a redstone signal at night


while true do
mTime = os.time()
if mTime >= 19 and mTime <= 24 or mTime >= 0 and mTime <= 6 then
rs.setOutput("right", true)
sleep(.5)
rs.setOutput("right", false)
sleep(.5)
else
rs.setOutput("right", false)
sleep(1)
end
end