Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- directions = {"north", "east", "south", "west"}
- local position = {}
- local direction = ""
- function init(x, y, z, dir)
- position = to_pos(x, y, z)
- direction = dir
- end
- function forward()
- if turtle.forward() then
- forward_increment()
- print_pos()
- end
- end
- function back()
- if turtle.back() then
- backward_increment()
- print_pos()
- end
- end
- function up()
- if turtle.up() then
- position = {
- x = position.x,
- y = position.y + 1,
- z = position.z
- }
- end
- end
- function down()
- if turtle.down() then
- position = {
- x = position.x,
- y = position.y - 1,
- z = position.z
- }
- end
- end
- function turnLeft()
- if turtle.turnLeft() then
- if direction == "north" then
- direction = "west"
- elseif direction == "east" then
- direction = "north"
- elseif direction == "south" then
- direction = "east"
- elseif direction == "west" then
- direction = "south"
- end
- end
- end
- function turnRight()
- if turtle.turnRight() then
- if direction == "north" then
- direction = "east"
- elseif direction == "east" then
- direction = "south"
- elseif direction == "south" then
- direction = "west"
- elseif direction == "west" then
- direction = "north"
- end
- end
- end
- function forward_increment()
- if direction == directions[1] then
- position = {
- x = position.x,
- y = position.y,
- z = position.z - 1
- }
- elseif direction == directions[2] then
- position = {
- x = position.x + 1,
- y = position.y,
- z = position.z
- }
- elseif direction == directions[3] then
- position = {
- x = position.x,
- y = position.y,
- z = position.z + 1
- }
- elseif direction == directions[4] then
- position = {
- x = position.x - 1,
- y = position.y,
- z = position.z
- }
- end
- end
- function backward_increment()
- if direction == directions[1] then
- position = {
- x = position.x,
- y = position.y,
- z = position.z + 1
- }
- elseif direction == directions[2] then
- position = {
- x = position.x - 1,
- y = position.y,
- z = position.z
- }
- elseif direction == directions[3] then
- position = {
- x = position.x,
- y = position.y,
- z = position.z - 1
- }
- elseif direction == directions[4] then
- position = {
- x = position.x + 1,
- y = position.y,
- z = position.z
- }
- end
- end
- function to_pos(x1, y1, z1)
- return {x=x1, y=y1, z=z1}
- end
- function print_pos()
- print("Position: (" .. position.x .. ", " .. position.y .. ", " .. position.z .. ")")
- end
- function goto(position)
- -- nothing
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement