Advertisement
ChaosBeing

patrol

Feb 27th, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.05 KB | None | 0 0
  1. os.loadAPI("action")
  2. redState = rs.getInput("bottom")
  3. hallway = true
  4. battery = 100 --need to implement
  5.  
  6.  
  7. function goShort()
  8.     count = 0
  9.     while count < 32 do
  10.         count = move(count)
  11.  
  12.         if count == 17 and hallway then
  13.             if not action.recharge() then
  14.                 hallway = not hallway
  15.             end
  16.         end
  17.     end
  18.    
  19.     turtle.turnRight()
  20.     hallway = not hallway
  21.     goLong()
  22. end
  23.  
  24.  
  25. function goLong()
  26.     count = 0
  27.     while count < 50 do
  28.         count = move(count)
  29.     end
  30.    
  31.     turtle.turnRight()
  32.     goShort()
  33. end
  34.  
  35. function move(count)
  36.     turtle.forward()
  37.     if turtle.detect() then
  38.         turtle.back()
  39.         turtle.turnRight()
  40.  
  41.         if count > 32 then
  42.             goShort()
  43.  
  44.         else
  45.             goLong()
  46.         end
  47.     end
  48.  
  49.     if not redState == rs.getInput("bottom") then
  50.         redState = rs.getInput("bottom")
  51.         return count + 1
  52.        
  53.     else
  54.         soundAlarm()
  55.         return count
  56.     end
  57. end
  58.  
  59. function soundAlarm()
  60.     --Debug!
  61.     print(rednet.send(3, "Alarm!")) -- 3 being the terminal ID
  62.     print("Alarm!")
  63. end
  64.  
  65.  
  66. rednet.open("right")
  67. term.clear()
  68. term.setCursorPos(1,1)
  69. print("Chaosoft Corp. Security Drone")
  70. goLong()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement