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

A Turtle places other Turtles and start them

Started by ChrisGW, 10 March 2014 - 07:11 AM
ChrisGW #1
Posted 10 March 2014 - 08:11 AM
Hello all turtle lovers!

I want to ask, if there is a possible to let a turtle place other turtles and start a programm on them.

I wrote a lua programm, which should mine a big area. I thought about to use many turtles, which mines different lines together, so it should be faster than just to use one turtle. For this approach it would be nice to let a turtle place all needed turtles and start them. Im using ComputerCraft v1.57.
I know that turtles can place turtles like normal blocks with direction [ turtle.place() ]. This is not the problem.
I get into problems, when i want to start this new placed turtle and let it run my programm for mining.

I thougt about follow setup, but havent succes with it yet.
There is a chef turtle which, place down all needed turtles. Behind the placed turtle is a diskDrive with a disk and startup programm. The startup programm let the placed turtle begin mining.

Chef Turtle lua programm:

local turtleNr = 1
while turtle.getItemCount(1) > 1 and turtleNr < 21 do
   print("Place Turtle -"..turtleNr)
   -- place turtle down
   turtle.select(1)
   while not turtle.placeDown() do
	  turtle.sleep(1)
   end

	sleep(5)

	-- let placed turtle reboot, so /disk/startup will be executed
   peripheral.call("bottom", "reboot")

   -- wait for turtles to go
   print("Wait for Turtle -"..turtleNr.."- to left station. ")
   while turtle.detectDown() do
	  turtle.sleep(1)
   end
   turtleNr = turtleNr+1
end

/disk/mineTurtle

local myTurtleNr = readTurtleNrFromDisk() -- read a number from disk useing "fs" api
-- go to my mine line
for k=1, myTurtleNr*6 do
   turtle.forward()
end

turtle.turnRight()
mining() -- mine a line like "tunnel" does
-- ...

the startup programm on the disk: /disk/startup

-- start mineTurtle programm
shell.run("/disk/mineTurtle")

I test this and got half success:
- When i use "lua" to test my code i got success and the placed turtle start. All fine.
- But when i let the lua programm run, my placed turtle doesnt start automatically, but when i click on the placed turtle the startup programm get executed and all works.

Im not sure if there is any kind of bug. Maybe the diskDrive doesnt connect on right way with the new placed turtle. Or maybe the reboot call doesnt work with this new placedTurtle. I dont know how turtles work intern and when a turtle turns into a turtle and not just a block, so im not sure about it.

So my Questions are:
- Does someone got experience with turtles, which start other turtles? How did you implement it?
- are there any mistakes in my appoarach and how can i fix them?
- or does i reach a limit from ComputerCraft?

Thanks for all advices!
Lyqyd #2
Posted 10 March 2014 - 02:33 PM
Use the turnOn peripheral method instead of reboot.
ChrisGW #3
Posted 14 March 2014 - 06:20 PM
Wow thanks, this was the mistake in my lua programm. Well i tried it all time long with reboot and i thought rebbot will do the same like turnOff() –> sleep() –> turnOn()
Now my programm is really funny with a army of turtles, which can start and craft them self :)/>