Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODEM = peripheral.wrap("left")
- function getVariables()
- write("Enter starting X: ")
- local start_x = read()
- if tonumber(start_x) == nil then error("Starting X should be a number!") end
- write("Enter starting Y: ")
- local start_y = read()
- if tonumber(start_y) == nil then error("Starting Y should be a number!") end
- write("Enter starting Z: ")
- local start_z = read()
- if tonumber(start_z) == nil then error("Starting Z should be a number!") end
- write("Enter width: ")
- local width = read()
- if tonumber(width) == nil then error("Width should be a number!") end
- write("Enter height: ")
- local height = read()
- if tonumber(height) == nil then error("Height should be a number!") end
- write("Enter depth: ")
- local depth = read()
- if tonumber(depth) == nil then error("Depth should be a number!") end
- write("Enter final facing direction: ")
- local direction = read()
- direction = string.lower(direction)
- if direction ~= "north" and direction ~= "east" and direction ~= "west" and direction ~= "south" then error("Direction should either be north, south, east or west") end
- return start_x, start_y, start_z, width, height, depth, direction
- end
- function refuelIfNeeded()
- end
- -- https://www.computercraft.info/forums2/index.php?/topic/1704-get-the-direction-the-turtle-face/
- function getFacingDirection()
- loc1 = vector.new(gps.locate(2, false))
- if not turtle.forward() then
- for j=1,6 do
- if not turtle.forward() then
- turtle.dig()
- else break end
- end
- end
- loc2 = vector.new(gps.locate(2, false))
- heading = loc2 - loc1
- return ((heading.x + math.abs(heading.x) * 2) + (heading.z + math.abs(heading.z) * 3))
- end
- function goToPosition(end_x, end_y, end_z, start_x, start_y, start_z, final_facing)
- current_x, current_y, current_z = start_x, start_y, start_z
- facing = getFacingDirection()
- print(facing)
- end
- function main()
- start_x, start_y, start_z, width, height, depth, direction = getVariables()
- current_x, current_y, current_z = gps.locate()
- goToPosition(start_x, start_y, start_z, current_x, current_y, current_z, direction)
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement