Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- turtle = require("turtle")
- --[[
- A little wrapper for ComputerCraft turtle.
- Intended for counting local coordinates.
- ]]--
- local position = {
- x = 0,
- y = 0,
- z = 0
- }
- local direction = "forward"
- local resultingTable = {
- moveUp = function()
- code, msg = turtle.up()
- if code then
- position.y = position.y + 1
- end
- return code, msg
- end,
- moveDown = function()
- code, msg = turtle.down()
- if code then
- position.y = position.y - 1
- end
- return code, msg
- end,
- moveForward = function()
- code, msg = turtle.forward()
- if code then
- position.y = position.x + 1
- end
- return code, msg
- end,
- moveBack = function()
- code, msg = turtle.back()
- if code then
- position.y = position.x - 1
- end
- return code, msg
- end,
- moveRight = function()
- code, msg = turtle.turnRight()
- if not code then
- return code, msg
- end
- direction = "right"
- code, msg = turtle.forward()
- if code then
- position.z = position.z + 1
- else
- return code, msg
- end
- code, msg = turtle.turnLeft()
- if code then
- direction = "forward"
- end
- return code, msg
- end,
- moveLeft = function()
- code, msg = turtle.turnLeft()
- if not code then
- return code, msg
- end
- direction = "left"
- code, msg = turtle.forward()
- if code then
- position.z = position.z - 1
- else
- return code, msg
- end
- code, msg = turtle.turnLeft()
- if code then
- direction = "left"
- end
- return code, msg
- end,
- fixDirection = function()
- if direction == "forward" then
- return true
- elseif direction == "left" then
- code, msg = turtle.turnRight()
- if code then
- direction = "forward"
- end
- return code, msg
- elseif direction == "right" then
- code, msg = turtle.turnLeft()
- if code then
- direction = "forward"
- end
- return code, msg
- else
- return false, "Incorrect direction"
- end
- end,
- getPosition = function()
- return position
- end,
- getDirection = function()
- return direction
- end
- }
- return resultingTable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement