mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-19 04:06:43 -04:00
Update go.lua
This commit is contained in:
parent
f7603f9a8a
commit
aeae1244f4
@ -1,23 +1,47 @@
|
|||||||
|
--[[ go, makes the robot go a specified number of blocks in a certain direction or turn around.
|
||||||
|
Author: Vexatos
|
||||||
|
]]
|
||||||
local robot=require("robot")
|
local robot=require("robot")
|
||||||
local shell=require("shell")
|
local shell=require("shell")
|
||||||
local args = shell.parse(...)
|
local args = shell.parse(...)
|
||||||
if #args<1 then
|
if #args<1 then
|
||||||
io.stderr:write("No direction specified\n")
|
print("'go' - Makes the robot go in a certain direction")
|
||||||
|
print("Usage:")
|
||||||
|
print("'go forward [number]' to make the robot go forward a number of blocks (defaults to 1)")
|
||||||
|
print("'go back [number]' to make the robot go backwards")
|
||||||
|
print("'go up [number]' to make the robot go upwards")
|
||||||
|
print("'go down [number]' to make the robot go downwards")
|
||||||
|
print("'go left [number]' to make the robot turn left a number of times")
|
||||||
|
print("'go right [number]' to make the robot turn right a number of times")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
local distance = args[2] or 1
|
||||||
|
|
||||||
|
if not tonumber(distance) or tonumber(distance) <= 0 then
|
||||||
|
io.stderr:write(distance..": not a positive number!\n")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
distance = math.floor(tonumber(distance))
|
||||||
|
local action
|
||||||
|
|
||||||
if args[1] == "forward" then
|
if args[1] == "forward" then
|
||||||
robot.forward()
|
action = robot.forward
|
||||||
elseif args[1] == "back" then
|
elseif args[1] == "back" then
|
||||||
robot.back()
|
action = robot.back
|
||||||
elseif args[1]=="left" then
|
elseif args[1] == "left" then
|
||||||
robot.turnLeft()
|
action = robot.turnLeft
|
||||||
elseif args[1]=="right" then
|
elseif args[1] == "right" then
|
||||||
robot.turnRight()
|
action = robot.turnRight
|
||||||
elseif args[1]=="up" then
|
elseif args[1] == "up" then
|
||||||
robot.up()
|
action = robot.up
|
||||||
elseif args[1]=="down" then
|
elseif args[1] == "down" then
|
||||||
robot.down()
|
action = robot.down
|
||||||
else
|
else
|
||||||
io.stderr:write(args[1]..": not a valid direction!\n")
|
io.stderr:write(args[1]..": not a valid direction!\n")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for i = 1,distance do
|
||||||
|
action()
|
||||||
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user