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

Rednet Instruction Transmission

Started by eggathachristie, 02 July 2012 - 07:29 PM
eggathachristie #1
Posted 02 July 2012 - 09:29 PM
I'm relatively new to Computercraft but I understand the basics, however I'm currently having an issue with transmitting a simple program to my turtle and was wondering if anyone could point me in the correct direction.

(I have rednet turned on on both the turtle and computer with modem attached)

Thanks in advance for any help or suggestions. :P/>/>
MysticT #2
Posted 02 July 2012 - 11:40 PM
Do you want to send the program and make the turtle execute it, or just instructions?
eggathachristie #3
Posted 03 July 2012 - 04:31 PM
Send and execute please. :P/>/>
MysticT #4
Posted 03 July 2012 - 04:48 PM
You need the fs and rednet apis.
To send a file over rednet you can do something like:

local file = fs.open("Path", "r")
if file then
  local s = file.readAll()
  file.close()
  rednet.send(id, s)
end

And then you receive it and execute it. Receiveing is easy, just a call to rednet.receive. To execute it there's two ways:
1) Save it to a file and use shell.run.
2) Use loadstring to run the received string directly.

local id, msg = rednet.receive()
local func = loadstring()
if func then
  func()
end

You can read about the apis in the wiki, and loadstring is in the lua manual.
eggathachristie #5
Posted 03 July 2012 - 05:12 PM
Thank you good sir, you have been most helpful. :P/>/>