3 posts
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/>/>
1604 posts
Posted 02 July 2012 - 11:40 PM
Do you want to send the program and make the turtle execute it, or just instructions?
3 posts
Posted 03 July 2012 - 04:31 PM
Send and execute please. :P/>/>
1604 posts
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.
3 posts
Posted 03 July 2012 - 05:12 PM
Thank you good sir, you have been most helpful. :P/>/>