Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- A basic turn to face directionality API for DanetOS3
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print("TurnToFace ERROR: Incorrect Usage. TurnToFace <direction>")
- return
- end
- function readCurDirection()
- local fileData = io.open("danetos3/direction.danet", "r")
- io.input(fileData)
- curDirection = io.read()
- io.close(fileData)
- return(curDirection)
- end
- function turnNorth()
- curDirection = readCurDirection()
- if curDirection == "north" then
- print("SUCCESS! Oriented NORTH.")
- elseif curDirection == "west" then
- shell.run("TurtleTurn right")
- print("SUCCESS! Oriented from WEST to NORTH.")
- elseif curDirection == "south" then
- shell.run("TurtleTurn right")
- shell.run("TurtleTurn right")
- print("SUCCESS! Oriented from SOUTH to NORTH.")
- elseif curDirection == "east" then
- shell.run("TurtleTurn left")
- print("SUCCESS! Oriented from EAST to NORTH.")
- else
- print("TurnToFace ERROR! Invalid direction in direction.danet. It said: " .. curDirection)
- end
- end
- function turnWest()
- curDirection = readCurDirection()
- if curDirection == "west" then
- print("SUCCESS! Oriented WEST.")
- elseif curDirection == "south" then
- shell.run("TurtleTurn right")
- print("SUCCESS! Oriented from SOUTH to WEST.")
- elseif curDirection == "east" then
- shell.run("TurtleTurn right")
- shell.run("TurtleTurn right")
- print("SUCCESS! Oriented from EAST to WEST.")
- elseif curDirection == "north" then
- shell.run("TurtleTurn left")
- print("SUCCESS! Oritented from NORTH to WEST.")
- else
- print("TurnToFace ERROR! Invalid direction in direction.danet. It said: " .. curDirection)
- end
- end
- function turnSouth()
- curDirection = readCurDirection()
- if curDirection == "south" then
- print("SUCCESS! Oriented SOUTH")
- elseif curDirection == "east" then
- shell.run("TurtleTurn right")
- print("SUCCESS! Oriented from EAST to SOUTH.")
- elseif curDirection == "north" then
- shell.run("TurtleTurn right")
- shell.run("TurtleTurn right")
- print("SUCCESS! Oriented from NORTH to SOUTH.")
- elseif curDirection == "west" then
- shell.run("TurtleTurn left")
- print("SUCCESS! Oriented from WEST to SOUTH.")
- else
- print("TurnToFace ERROR! Invalid direction in direction.danet. It said: " .. curDirection)
- end
- end
- function turnEast()
- curDirection = readCurDirection()
- if curDirection == "east" then
- print("SUCCESS! Oritented EAST.")
- elseif curDirection == "north" then
- shell.run("TurtleTurn right")
- print("SUCCESS! Oriented from NORTH to EAST.")
- elseif curDirection == "west" then
- shell.run("TurtleTurn right")
- shell.run("TurtleTurn right")
- print("SUCCESS! Oriented from WEST to EAST.")
- elseif curDirection == "south" then
- shell.run("TurtleTurn left")
- print("SUCCESS! Oriented from SOUTH to EAST.")
- else
- print("TurnToFace ERROR! Invalid direction in direction.danet. It said: " .. curDirection)
- end
- end
- if tArgs[1] == "north" then
- turnNorth()
- elseif tArgs[1] == "west" then
- turnWest()
- elseif tArgs[1] == "south" then
- turnSouth()
- elseif tArgs[1] == "east" then
- turnEast()
- else
- print("TurnToFace ERROR: Incorrect args. Must be north, south, east, or west.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement