Keltaith

Untitled

May 16th, 2012
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local nBroadcastTime = 300
  2. local nTime = 1500
  3.  
  4. local function createtime()
  5.  
  6.  
  7.     term.clear()
  8.     term.setCursorPos( 1,1 )
  9.     print( "Set the settings.")
  10.  
  11.     write("How often should trees harvest?")
  12.     nBroadcastTime = tonumber(read())
  13.    
  14.  
  15.     file = io.open("timesettings.txt" , "w")
  16.     if file == nil then
  17.         return
  18.     end
  19.  
  20.     file:write( nBroadcastTime )
  21.     file:write( "\n" )
  22.  
  23.     file:close()
  24.  
  25.     term.clear()
  26.     term.setCursorPos( 1,1 )
  27.     print( "Working" )
  28.  
  29.  
  30. end
  31.  
  32.  
  33.  
  34. local function loadtime()
  35.  
  36.     file = io.open( "timesettings.txt" , "r")
  37.     while true do
  38.         line = file:read()
  39.         if line == nil then break end
  40.  
  41.         nBroadcastTime = tonumber(line)
  42.        
  43.         file:close()
  44.  
  45.         return true
  46.  
  47.     end
  48.  
  49.     file:close()
  50.  
  51.     return false
  52.  
  53. end
  54.  
  55.  
  56.  
  57.  
  58. term.clear()
  59. term.setCursorPos ( 1,1 )
  60. print( "Starting Logger Broadcast...")
  61.  
  62. if fs.exists( "timesettings.txt") then
  63.     if not loadtime() then
  64.         createtime()
  65.     end
  66.  
  67.     term.clear()
  68.     term.setCursorPos( 1,1 )
  69.     print( "Cycling")
  70.     stopTimer()
  71. else
  72.     createtime()
  73. end
  74.  
  75. rednet.open("right")
  76.  
  77.  
  78.    
  79.  
  80.  
  81.  
  82. local stopTimer = os.startTimer(nTime)
  83. local broadcastTimer = os.startTimer(nBroadcastTime)
  84. while true do
  85.   local evt, arg = os.pullEvent()
  86.   if evt == "timer" then
  87.     if arg == broadcastTimer then
  88.       rednet.broadcast("startLoging")
  89.       broadcastTimer = os.startTimer(nBroadcastTime)
  90.     elseif arg == stopTimer then
  91.       break
  92.     end
  93.   elseif evt == "char" then
  94.     if arg == "s" then
  95.           break
  96.     end
  97.   end
  98. end
Advertisement
Add Comment
Please, Sign In to add comment