Posted 28 February 2012 - 02:49 AM
Hey guys, Im not really to much of a coder but I do know the basics and how to use google. So far ComputerCraft has really gotten me thinking along some new lines. I have a few programs cobbled together from other sources and modified but now I am seeking some help in moving them to the next level of complexity.
I have a wireless turtle program to recieve commands from a computer, a computer program to send those commands, and a thrid program that I am trying to figure out how to integrate.
here is the computer.
here is the little bit of code I have so far for the host to recieve and store the direction and distance to move.
this works just fine, however I am totally stuck on sending this to the client.
I have a wireless turtle program to recieve commands from a computer, a computer program to send those commands, and a thrid program that I am trying to figure out how to integrate.
here is the computer.
-- computer
print("type down to run the down program")
print("type dig to run the dig program")
print("type move to run the move program")
digBot = 0
digBot2 = 1
digBot3 = 20
digBot4 = 3
digBot5 = 19
digBot6 = 5
direction = 0
distance = 0
rednet.open('right') -- open wifi port
while true do -- start infinite loop
key = read()
if key == 'down' then
rednet.send(digBot, 'down')
print('sent down')
rednet.send(digBot2, 'down')
print('sent down')
rednet.send(digBot3, 'down')
print('sent down')
rednet.send(digBot4, 'down')
print('sent down')
rednet.send(digBot5, 'down')
print('sent down')
rednet.send(digBot6, 'down')
print('sent down')
end
if key == 'dig' then
rednet.send(digBot, 'dig')
print('sent dig')
rednet.send(digBot2, 'dig')
print('sent dig')
rednet.send(digBot3, 'dig')
print('sent dig')
rednet.send(digBot4, 'dig')
print('sent dig')
rednet.send(digBot5, 'dig')
print('sent dig')
rednet.send(digBot6, 'dig')
print('sent dig')
turtle.forward()
turtle.forward()
turtle.down()
turtle.down()
end
end
here is the turtle.
-- turtle
write("host id #")
sender = read()
--ask for host id
shell.run('clear') --clear the screen
rednet.open("right") --open the wifi port
x=1
while x == 1 do --start loop
action, senderID, text = os.pullEvent() --wait for input
if action == "rednet_message" then --if its a wireless message do
if text == 'down' then
shell.setDir('rom')
shell.run('/rom/down')-- go forward
print(working)
end
if text == 'dig' then -- if the up button is pressed
shell.setDir('rom')
shell.run('/rom/dig', '30')
print(working)
end
end
end
and here is the last program I am trying to remotely control from the computer. Basically I am stuck on using rednet to send the variables to the client turtle before it runs the program. I would like to type move, then have it prompt me for the direction then the distance. I am a little confused with the whole wireless rednet api.
args = {...}
args2 = tonumber(args[2])
while true do
if args[1] == 'left' then
turtle.turnLeft()
while args2 > 0 do
turtle.forward()
args2 = args2 - 1
end
turtle.turnRight()
break
end
if args[1] == 'right' then
turtle.turnRight()
while args2 > 0 do
turtle.forward()
args2 = args2 - 1
end
turtle.turnLeft()
break
end
if args[1] == 'forward' then
while args2 > 0 do
turtle.forward()
args2 = args2 - 1
end
break
end
if args[1] == 'back' then
while args2 > 0 do
turtle.back()
args2 = args2 - 1
end
break
end
if args[1] == 'up' then
while args2 > 0 do
turtle.up()
args2 = args2 - 1
end
break
end
if args[1] == 'down' then
while args2 > 0 do
turtle.down()
args2 = args2 - 1
end
break
end
end
here is the little bit of code I have so far for the host to recieve and store the direction and distance to move.
if key == 'move' then
print("what direction")
direction = read()
print("how far")
distance = tonumber(read())
print(distance)
print(direction)
end
this works just fine, however I am totally stuck on sending this to the client.