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

Starting a turtle program when a computer receives a redstone input.

Started by Idesta, 13 January 2013 - 06:01 AM
Idesta #1
Posted 13 January 2013 - 07:01 AM
The title is kinda bland, but here is the back story.

I created a turtle to farm a tree over and over and over again, however sometimes the tree doesn't grow. I've placed some redstone repeaters that feed into the logs so that when the tree is grown power is sent out and into the back of the computer. Well once the computer recives the power i would like for the turtle to begin it's program for harvesting and planting the tree.

For the computer I have this so far.


local event, p1 = os.pullEvent("redstone")
  if rs.Input("back") then
    rednet.open ("left")
    rednet.broadcast

As far as i know, I need it to send a message to the turtle then when the turtle receives that message it begins, I just don't know how to set all that up.
Kingdaro #2
Posted 13 January 2013 - 07:07 AM
You pretty much had all of the sender script right there, and the turtle receiving script isn't really all that difficult either. Only thing is the message you want to send. And sometimes, I find it more "professional" and "cleaner" to close the rednet modem when you're not using it, even though there's really no harm in keeping it open all the time.


local event, p1 = os.pullEvent("redstone")
  if rs.getInput("back") then
    rednet.open ("left")
    rednet.broadcast("START MINING DAMNIT")
    rednet.close ("left")
  end

So then the turtle would be running this code:

while true do
  rednet.open("right")
  local id, msg = rednet.receive()
  rednet.close("right")
  if msg == "START MINING DAMNIT" then
    doMiningStuff()
  end
end

Where "doMiningStuff()" is just the code for your turtle's harvesting/replanting actions.
Idesta #3
Posted 13 January 2013 - 07:25 AM
Thank you Lua Maniac, I had been doing research on it for about an hour before giving up and just asking.
crazyguymgd #4
Posted 13 January 2013 - 08:02 AM
This is a fine method because it gives you some experience with rednet and redstone apis but it's pretty much unnecessary. I assume this is with using bonemeal so as long as you keep a log in the turtles inventory, you would bonemeal the sapling, then use a compare with the log. If the tree has grown, the compare will return true, if it's still a sapling, comopare will be false and you can just bonemeal some more.
remiX #5
Posted 13 January 2013 - 08:30 AM
rednet.broadcast("START MINING DAMNIT")

Nice xD

Thank you Lua Maniac, I had been doing research on it for about an hour before giving up and just asking.

His name isn't Lua Maniuac, his name is Kingdaro. Lua Maniac is his title