Posted 26 September 2012 - 09:01 PM
Hi guys, so I started Direwolf20's ComputerCraft tutorials yesterday evening and I decided to install it on my server for me and my mate to mess with.
My mate asked me to make a simple turtle interface program so that he could move a turtle around and dig and do really basic commands (he wanted something to be able to dig obsidian as he's lazy) so I made this:
Now I'm pretty sure that is no where the best way to do it, but it works… except, I want to be able to type "forward 20" and have the turtle move forward 20 blocks, now I know how to loop it 20 times (well kinda, but I'm sure I can figure it out) but how can I take that input of "forward 20" and put it into 2 variables so I can execute forward, 20 times?
Sorry for the kinda drawn out question, thanks in advance for any help you can give me :P/>/>.
My mate asked me to make a simple turtle interface program so that he could move a turtle around and dig and do really basic commands (he wanted something to be able to dig obsidian as he's lazy) so I made this:
Spoiler
local version = 1.1
function forward()
turtle.forward()
end
function backward()
turtle.backward()
end
function left()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
end
function right()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
end
function up()
turtle.up()
end
function down()
turtle.down()
end
function turnRight()
turtle.turnRight()
end
function turnLeft()
turtle.turnLeft()
end
function dig()
turtle.dig()
end
function digDown()
turtle.digDown()
end
function digUp()
turtle.digUp()
end
function fuelLevel()
print("Fuel Level: "..turtle.getFuelLevel())
end
function refuel()
turtle.refuel()
end
function exitTurtleUI()
term.clear()
term.setCursorPos(1,1)
print("THANK YOU FOR USING T.U.I 1.0")
os.reboot()
end
function tuiHelp()
term.clear()
term.setCursorPos(1,1)
print("Available Commands:")
print("forward, back")
print("left, right")
print("up, down")
print("tright, tleft")
print("dig, digup, digdown")
print("fuel, refuel")
print("exit, help")
print()
print("Press enter to continue...")
read()
end
local run = 0
term.clear()
term.setCursorPos(1,1)
term.write("WELCOME TO T.U.I "..version)
sleep(2)
while run ~= 1 do
term.clear()
term.setCursorPos(1,1)
term.write("Please enter Turtle do: ")
command = read()
if command == "forward" then
forward()
elseif command == "backward" then
backward()
elseif command == "left" then
left()
elseif command == "right" then
right()
elseif command == "up" then
up()
elseif command == "down" then
down()
elseif command == "tright" then
turnRight()
elseif command == "tleft" then
turnLeft()
elseif command == "dig" then
dig()
elseif command == "digup" then
digUp()
elseif command == "digdown" then
digDown()
elseif command == "fuel" then
fuelLevel()
elseif command == "refuel" then
refuel()
elseif command == "exit" then
exitTurtleUI()
elseif command == "help" then
tuiHelp()
else
print("INVALID COMMAND")
os.sleep(1)
end
end
Now I'm pretty sure that is no where the best way to do it, but it works… except, I want to be able to type "forward 20" and have the turtle move forward 20 blocks, now I know how to loop it 20 times (well kinda, but I'm sure I can figure it out) but how can I take that input of "forward 20" and put it into 2 variables so I can execute forward, 20 times?
Sorry for the kinda drawn out question, thanks in advance for any help you can give me :P/>/>.