This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
shadowst17's profile picture

Telling a turtle to tunnel form a computer

Started by shadowst17, 11 February 2014 - 01:24 PM
shadowst17 #1
Posted 11 February 2014 - 02:24 PM
This is driving me insane, i'm a complete idiot when it comes to this stuff and i cant figure out how to send the correct code to get the turtle to tunnel. i;ve tried

turtle
rednet.open("right")
rednet.receive()

computer
rednet.broadcast("shell.run("tunnel", 4)")

the turtle gets it and gives me strange few numbers but doesn't actually make it tunnel.

Also while i'm asking question how would i go about making it return again, i guess i could make another program that i can run that makes it turns around but is there a way to edit the actual tunnel program so it does this automatically?
CometWolf #2
Posted 11 February 2014 - 02:50 PM
I have no experience with the built in tunnel program, but dosen't it return on it's own already? Anyways, your understanding of rednet is way off base. Everything sent and received through rednet will be a string. In short this means it's just a piece of text, not a program, not a piece of code for your turtle to execute. What you need to do instead in this case, is this
turtle

rednet.open"right"
local _id,msg = rednet.receive() -- rednet.receive returns 3 variables, the first is the sender ID, the second is the message, and the thrid is the distance from the receiver to the sender. We want the 2nd one, so i'll save that to the variable msg
shell.run(msg) -- note how im passing the result of rednet.receive to the function shell.run on the turtle, instead of trying to send the function itself
computer

rednet.open"whatever side it's on"
rednet.broadcast"tunnel 4"
CMaster #3
Posted 11 February 2014 - 02:52 PM
All that rednet does is send a string (in the next update, also numbers and tables. For now, if you want to send a table, you have to use textutils.serialize())
If you want it to do something, you'd need to actually take some action with rednet.receive()

Eg:


Turtle:

rednet.open("right")
id, program = rednet.receive()
id, argument = rednet.receive()
shell.run(program, argument)

Computer:

rednet.open(<whatever side the modem is>)
rednet.broadcast("tunnel")
rednet.broadcast("4")

Obviously the above program is pretty limited - it expects a certain number of arguments, and will fall to pieces as soon as you have any other broadcasts going on.
But then those are important problems for you to solve.

It's possible to look at and modify the basic tunnel program. It#s pretty limited (and inefficent) mind.
Just copy out tunnel from rom/programs, or look around in the programs forum here for already developed alternatives (My multi-functional replacement is here: http://pastebin.com/RFtfi6gx)
Edited on 11 February 2014 - 01:55 PM
Lyqyd #4
Posted 11 February 2014 - 03:22 PM
The information provided previously about rednet being limited to strings is incorrect. At least as far back as version 1.57, I believe (but certainly 1.58), rednet can transport strings, numbers and tables. Booleans as well, I believe. Using an up-to-date version of the mod means that you won't be limited to strings. Function and thread values cannot be sent through rednet, however.
CometWolf #5
Posted 11 February 2014 - 03:34 PM
Does it actually send the table, or just automatically serialize and unserialize?
Lyqyd #6
Posted 11 February 2014 - 03:45 PM
There is no serialization or unserialization performed on it on the Lua side of things. It does create a "new" table, so sending one table doesn't mean that two computers now share the same table reference.
CMaster #7
Posted 11 February 2014 - 03:49 PM
The information provided previously about rednet being limited to strings is incorrect. At least as far back as version 1.57, I believe (but certainly 1.58), rednet can transport strings, numbers and tables. Booleans as well, I believe. Using an up-to-date version of the mod means that you won't be limited to strings. Function and thread values cannot be sent through rednet, however.

Apologies - I'd thought I'd read it was an upcoming feature with 1.6

Means I can probably stop using my homebrew wrapper for rednet then (as old as MC1.2.5)

So yeah, best thing to do is probably send a table of program name and params, and then sort them out again somehow on the other end,
CometWolf #8
Posted 11 February 2014 - 03:51 PM
Well obviously, however awesome that would be :P/> I assume sending tables directly works with the modem api aswell then? I don't use rednet.
Lyqyd #9
Posted 11 February 2014 - 04:58 PM
Yeah, the transmit call offered by the modems fully supports those types.
shadowst17 #10
Posted 12 February 2014 - 02:53 PM
Awesome I can now tell the turtle to tunnel but how would i get him to return?