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

LUA Question How to make a turtle copy to another turtle

Started by guamie, 30 January 2013 - 07:57 PM
guamie #1
Posted 30 January 2013 - 08:57 PM
Greetings!

Here is what I'm trying to do:


count=1
while count <= 36 do
turtle.place()
t=peripheral.wrap("front")
fs.copy("paths/"..count,"startup")
fs.copy("return/"..count"r","return")
fs.copy("dark","dark")
t.turnOn()
count = count +1
rednet.receive()
end
count=1
while count <= 36 do
if turtle.detect() then
turtle.dig()
else
turtle.sleep(.1)
end
count=count+1
end
turtle.forward()
while true do
turtle.turnRight()
end


However, I am not sure how to specify the turtle i'm trying to copy to.

the end result I'm trying to accomplish is that each turtle is deployed by the main turtle, then main turtle copies the program the turtle is going to run along wiht a secondary program which is just a path back tot he starting point.

I've turned this from a castle builder into a turtle version of a IC quarry. basically it uses 36 turtles to dig a 60x60 hole…

Once it is finished I planned on posting it on the forums to see what everyone thought. the program also uses rednet to syncronize the digging, hoping to make em like synchronized swimmers :D/>

EDIT:

If this isn't possible. Which portion of the wiki should I focus on to:

instead of the main turtle copying files, use a floppy disk to copy the files, however I would want to be able to store the count someway ( can I >> to another program in lua?) so that each turtle isn't given all the files, just the ones it needs for its specific task. basically just write count to another file that startup calls on to know its next file to copy. is this possible to do? Like, can I cat a file in lua somehow and then take what i've pulled and use it as a variable?
ChunLing #2
Posted 31 January 2013 - 02:54 AM
You cannot directly access the filesystem of a turtle or computer from an adjacent turtle/computer. You must use a startup disk in a drive that will be next to the turtle when it is turned on.

Fortunately, it isn't too hard to write a startup program that not only copies a program to the turtle, but keeps track of how many times the program has run by writing that information to another file on the disk, after reading that file (if it exists) each time.
guamie #3
Posted 31 January 2013 - 06:55 AM
What would be the most efficient way to do this?
Doyle3694 #4
Posted 31 January 2013 - 07:26 AM
First turtle:

turtle.select(15)
turtle.place()
turtle.select(14)
turtle.drop()
turtle.up()
turtle.select(16)
turtle.place()
newTurtle = peripheral.wrap("front")
newTurtle.turnOn()
With a diskdrive in 15, the disk in 14, and the turtle in 16

The disk should have a program on it called startup, which looks like this:

function copyTo(file)
   fs.copy("disk/"..file, "/")
end
copyTo("autominer") -- This is ofcourse a example, it could just as well be anything from a password program to a hack to a lumberjack
The disk should also contain what you want to copy(the things you specify in the code above). You can ofcourse add more copyTo()'s too :)/>
guamie #5
Posted 31 January 2013 - 08:57 AM
Cool, but this doesn't fully do waht I was looking for.

The disk has 72 files. 2 per turtle, (36 turtles)

I've done an easy naming convention for my testing some example program names:

1
1r
2
2r
3
3r

turtle one needs 1 and 1r, turtle two need 2 and 2r etc

what i want, is when the startup program runs, it rewrites "blarg" (my file to track which turtle it is on, and can use this number to pull the right files.

fs.copy("disk/paths/"..count,"startup")
fs.copy("disk/return/"..count"r","return")

so really i need two things, one, I need to know how to have the main turtle call this secondary program "blarg" and pull out the number stored there and also I need to know how to have it write to the file, so I can have it add 1 each time it runs.

I've been looking at fs.open for this, but I find myself scratching my head a little bit about how is best to use the command.
Doyle3694 #6
Posted 31 January 2013 - 09:08 AM
I think you could easily modify my code with some for loops to make it work like you want.
guamie #7
Posted 31 January 2013 - 09:17 AM
i'm still a newb workig with lua, so time to research for loops!

Thanks for the function doyle!