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

[Question] Command set repeats and turtle activation.

Started by Menschenfeind, 28 September 2012 - 05:01 AM
Menschenfeind #1
Posted 28 September 2012 - 07:01 AM
I should preface this by saying I have absolutely no business playing with computercraft. I am not a programmer and never will be, I just happened into CC after I got tired of vanilla MC and fell into IC2 and BC, and figured I should try some others. So for all intents and purposes I am a complete noob to this, and should be treated as such.
I've began toying with turtles and my first project has been to create an automatic wheat farmer. This is what I have so far:

Spoiler–Farm–
turtle.select(1)
turtle.refuel(1)
print(turtle.getFuelLevel())

turtle.dig()
turtle.suck()
turtle.forward()

for i=1,7 do
turtle.dig()
turtle.suck()
turtle.forward()
turtle.turnLeft()
turtle.turnLeft()
turtle.dig()
turtle.select(2)
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
end

turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.turnLeft()

So it farms 7 blocks in front of it and then turns and moves to the next row over, I know it's not complete but I don't want to go any further until I know some more.
My first question is, is there a way to "name" the looped set so that I can just have the turtle do it again (with "do" I would assume)? Or by some other method?

My second question: is there a way to activate a turtle program with a redstone signal? Or do I have to manually do it through startup/running the program?

I've attempted to google the answers to these questions but have been unsuccessful.
Also, any pointers would be nice, I'm pretty much self taught so I'm sure I'm doing several things either wrong or inefficently.
Thanks for any assistance.
Luanub #2
Posted 28 September 2012 - 07:23 AM
So for your first question yes use functions. Here is an example

local function farm()
for i=1,7 do
turtle.dig()
turtle.suck()
turtle.forward()
turtle.turnLeft()
turtle.turnLeft()
turtle.dig()
turtle.select(2)
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
end
end

farm() -- to call it

2nd answer is with a computer you can turn the turtle on as if it was a peripherall. Otherwise there is no remote way of turning on a turtle.
Menschenfeind #3
Posted 28 September 2012 - 07:28 AM
I see, I read some code that used functions but I wasn't sure if the terms they were using afterwards (In this case you used farm()), had specific meaning, or if they were like this and "named".
Thank you for answering my questions.