Advertisement
NAPTlME

Motor4

Jul 5th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. --Motor4
  2. --NAPTlME
  3.  
  4. print(os.getComputerID())
  5.  
  6. rednet.open('right')
  7.  
  8. function update()
  9.   --fs.delete("open")
  10.   local y = fs.open('open','w')
  11.   y.writeLine(north)
  12.   y.writeLine(south)
  13.   y.writeLine(east)
  14.   y.writeLine(west)
  15.   y.writeLine(up)
  16.   y.writeLine(down)
  17.   y.close()
  18. end
  19.  
  20. if not fs.exists('open') then
  21.   north = "0"
  22.   south = "0"
  23.   east = "0"
  24.   west = "0"
  25.   up = "0"
  26.   down = "0"
  27.   update()
  28.   os.reboot()
  29. else
  30.   local z = fs.open('open','r')
  31.   north = tonumber(z.readLine())
  32.   south = tonumber(z.readLine())
  33.   east = tonumber(z.readLine())
  34.   west = tonumber(z.readLine())
  35.   up = tonumber(z.readLine())
  36.   down = tonumber(z.readLine())
  37.   z.close()
  38. end
  39. m = peripheral.wrap('bottom')
  40. sleep(0.25)
  41.  
  42.  
  43. function retract(n)
  44.   m.move(n,false,false)
  45. end
  46. function moving()
  47.   if west >0 then
  48.     west = west - 1
  49.     update()
  50.     retract(4)
  51.   elseif north > 0 then
  52.     north = north - 1
  53.     update()
  54.     retract(2)
  55.   elseif down >0 then
  56.     down = down - 1
  57.     update()
  58.     retract(0)
  59.   elseif up >0 then
  60.     up = up -1
  61.     update()
  62.     retract(1)
  63.   elseif south > 0 then
  64.     south = south - 1
  65.     update()
  66.     retract(3)
  67.   elseif east > 0 then
  68.     east = east - 1
  69.     update()
  70.     retract(5)
  71.  end
  72. end
  73. moving()
  74. while true do
  75.   id,msg = rednet.receive()
  76.   if id == 100 then
  77.     if msg == "open" then
  78.       west = 3
  79.       north= 3
  80.       down = 5
  81.       update()
  82.       os.reboot()
  83.     elseif
  84.       msg == "close" then
  85.       up = 5
  86.       south= 3
  87.       east= 3
  88.       update()
  89.       os.reboot()
  90.     end
  91.   end
  92. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement