I have an advanced computer with a wireless modem in my world as well as several Wireless turtles. Now I want to sent a program from that computer to the turtle and run it.

I looked up the modem API on the ComputerCraft website but I could not find a way to do it.

Do I need advanced turtles? Are there advanced turtles in FTB Mindcrack 1.4.7 (I don't know the version of ComputerCraft in the Mindcrack version of FTB)

How can I send programs to the turtles and run them from my advanced computer?

  • ftbwiki.org/Lua_(ComputerCraft) does this help – random user Dec 29 '15 at 5:03
  • The name of a program must be a single string of characters. Multiple words may be placed together if needed but it is suggested that the first letter of each subsequent word be capitalized. This is commonly called camel-case notation in programming as the capital letters look like the humps on the back of a camel. Save your program: To save your program you will need to make a disk drive and a floppy disk. Place your disk drive next to your computer, and put in your floppy. Then type "copy <program> disk" where <program> is the name of the program you wish to save. – random user Dec 29 '15 at 5:04
  • Access a program on a floppy disk: To access a program on a disk you will need to first change the directory you are in to the disk directory. To do so type "cd disk". Now all you have to do is type the name of your program and any inputs it needs. Alternatively, you can type "disk/<program>", where <program> is the name of the program in the disk directory. – random user Dec 29 '15 at 5:04
  • Could you clarify in an awnser? – BRHSM Dec 29 '15 at 12:54

Let me begin by saying that the Rednet API in ComputerCraft is... fun. I imagine about as fun as any given netcoding could ever be, I suppose.

You can do one of two things. You can either transfer your program to the turtle with a floppy disk and send it a command to run that program from the computer, or, you can actually push an entire lua program to a computer, and then order it to execute that program. I will be covering both solutions in this answer.

You can transfer a program from a computer to a turtle using a floppy disk. To transfer a program between computers, you will need a disk drive and a blank floppy disk. Place the disk drive next to your advanced computer, and put your floppy disk in it. You can copy a file to the disk with copy <file> disk. Now you have your program stored on the floppy disk. You can now use the floppy disk to put the program on the Turtle. Place your turtle down next to the disk drive. You can copy the file from the disk to the turtle with copy disk/<file> <file>. Now the turtle has the program. Make sure you name that turtle with label set <name> so that all programs will be stored when you break him.

Now you have a file called <file> on your turtle. Let's set up a program on the turtle called server, which will listen for a message, and then execute that message in the shell.

while true do
   senderID, message, distance = rednet.receive()
   if message == "exit" then

This program will listen for a message, execute it as a shell command, and then start listening again. So if you send it excavate 10, it will start the excavate program with argument 10, or, if you send it <file>, it will run your newly copied program. The corresponding client program could be something like this:

while true do
   input = read()
   rednet.send(<ID>, input)
   if input == "exit" then

Where <ID> is the ID of the receiving turtle. This will allow you to type commands on the advanced computer to be received by the turtle.

To push an entire lua program to a turtle is a little more complicated, but not much. You will need to use the fs API to access the filesystem of the turtle and computer, in addition to the shell API from earlier.

Start with a program called send. This program's job is to read from a file and send that file as a string over rednet. You can accomplish this using the fs API. Let's start by opening a file from the argument list and initializing everything like that:

args = {...}
infile = fs.open(args[1], "r")
filestring = infile.readAll()

This will take an input file from an argument and send it over rednet as a string to the computer at <ID>. The turtle will then have to write this string to a file and run that file.

while true do
   file = rednet.receive()
   contents = rednet.receive()
   outfile = fs.open(file, "w")

This should receive a filename followed by a large string with the file contents, write that to the filename, and run that file.

So you can do this either way. You can either predefine commands on the turtle, or you can send an entire lua file as a message and have the turtle write that message to a local file before executing it. Either way works.

| improve this answer | |
  • This code has been tested and should work in ComputerCraft for Minecraft 1.4.7. The only potential issue I can think of is a buffer overflow or something. – Unionhawk Dec 30 '15 at 3:30
  • Thanks for this explanation. I'm interested in the option to push an entire Lua program, but I'm confused about the args = {...} line in the code. Is this where I specify the program/file that I wish to send over rednet? If so, how exactly do I reference it within the curly braces? If not, how do I specify the program/file that I want to relay? – EJ Mak Dec 25 '19 at 15:57
  • @EJMak args = {...} in Lua takes the arguments passed to the command (for instance, in excavate 10, the argument 10) and assigns it to a variable as an array. This line allows the program to take a file name as input (send program) and should be left unmodified. The only spots that should be modified are indicated by angle brackets (<ID> etc) – Unionhawk Dec 25 '19 at 17:01
  • So, if I have a program on the sending computer called foo.lua, would that line in my code be written like this?: args = {foo} – EJ Mak Dec 25 '19 at 17:07
  • 1
    @EJMak No, that line should be left as args = {...}, and you can send foo by running send foo. – Unionhawk Dec 25 '19 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.