Godleydemon

platform

Jun 10th, 2013
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.06 KB | None | 0 0
  1. local turtleId
  2. local isWirelessTurtle
  3. local messageOutputFileName
  4. local tArgs = {...}
  5. local length = tonumber(tArgs[1])
  6. local width = tonumber(tArgs[2])
  7. local turnRight = true
  8. local slot = 1
  9.  
  10.  
  11.  
  12. isWirelessTurtle = peripheral.isPresent("right")
  13. if (isWirelessTurtle == true) then
  14.   turtleId = os.getComputerLabel()
  15.   rednet.open("right")
  16. end
  17.  
  18. function writeMessage(message)
  19.     print(message)
  20.  
  21.     -- If this turtle has a modem, then write the message to red net
  22.     if (isWirelessTurtle == true) then
  23.       if (turtleId == nil) then
  24.         rednet.broadcast(message)
  25.       else
  26.         -- Broadcast the message (prefixed with the turtle's id)
  27.         rednet.broadcast("[".. turtleId.."] "..message)
  28.       end
  29.     end
  30.  
  31.     if (messageOutputFileName ~= nil) then
  32.       -- Open file, write message and close file (flush doesn't seem to work!)
  33.       local outputFile = io.open(messageOutputFileName, "a")
  34.       outputFile:write(message)
  35.       outputFile:write("\n")
  36.       outputFile:close()
  37.     end
  38. end
  39.  
  40. if width == nil then
  41.     print("1. Place turtle facing direction of said platform on left side.")
  42.     print("2. Load turtle with materials for the platform.")
  43.     print("3. Type 'platform <length> <width>'")
  44. end
  45.  
  46. writeMessage("Beginning to build Platform")
  47.  
  48. turtle.select(slot)
  49.  
  50. turtle.dig()
  51. turtle.forward()
  52.  
  53. for j = 1, width, 1 do
  54.  
  55.   for i = 1, length, 1 do
  56.     if turtle.getItemCount(slot) == 0 then
  57.       slot = slot + 1
  58.       turtle.select(slot)
  59.       turtle.digDown()
  60.       turtle.placeDown()
  61.     else
  62.         turtle.digDown()
  63.       turtle.placeDown()
  64.     end
  65.    
  66.     if i < length then
  67.         turtle.dig()
  68.       turtle.forward()
  69.     end
  70.  
  71.   end
  72.  
  73.   if j < width then
  74.  
  75.     if turnRight == true then
  76.       turtle.turnRight()
  77.       turtle.dig()
  78.       turtle.forward()
  79.       turtle.turnRight()
  80.       turnRight = false
  81.     else
  82.       turtle.turnLeft()
  83.       turtle.dig()
  84.       turtle.forward()
  85.       turtle.turnLeft()
  86.       turnRight = true
  87.     end
  88.    
  89.   end
  90.  
  91. end
  92.  
  93. writeMessage("Finished Building Platform")
Advertisement
Add Comment
Please, Sign In to add comment