Guest User

Untitled

a guest
Mar 17th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. local wlk = { ... }
  2. local totalMoved = 0
  3. local length, width = tonumber(wlk[1]), tonumber(wlk[2])
  4.  
  5. if #wlk ~= 2 or type(length) ~= "number" or type(width) ~= "number" then --checking user'sInput
  6.   print( "use the program properly!" )
  7.   return
  8. end
  9.  
  10. local function walkLength() --move forward for (length) times
  11.   for i = 2, length do
  12.     turtle.forward()
  13.     totalMoved = totalMoved + 1
  14.   end
  15. end
  16.  
  17. face = 0
  18.  
  19. local function altTurn() --alternating turn (left, left),(right, right)
  20.   if face < 2 then
  21.     face = face+1
  22.     turtle.turnLeft()
  23.   elseif face == 2 then
  24.     face = face+1
  25.     turtle.turnRight()
  26.   else
  27.     face = 0
  28.     turtle.turnRight()
  29.   end
  30. end
  31.  
  32. local cWidth = 0
  33. turtle.turnRight()
  34. while width ~= cWidth do
  35.   print('Percent done: '..math.floor(totalMoved / (length * width) * 100)..'%')
  36.   walkLength()
  37.   cWidth = cWidth+1
  38.   if width ~= cWidth then -- rechecking
  39.     altTurn()
  40.     turtle.forward()
  41.     altTurn()
  42.   end
  43. end
Advertisement
Add Comment
Please, Sign In to add comment