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

newbi questions

Started by daveuk, 01 September 2012 - 03:36 PM
daveuk #1
Posted 01 September 2012 - 05:36 PM
hi guys,
I am VERY new to programming but am relay enjoying learning,

anyway here is my question

I have managet to get turtles to go out plant trees and evan made programs for a turtle to chop down a tree ( I know! how clever am I)

but what i am trying to do is save a chunk of programing into something short i can re use ie

turtle.forward()
chop down tree
turtle forward 5 spces
chop down another tree
and so on and so on

( i know this is not close to correct prgraming but just to get my idea forward)

so what i want is "chop down tree" to contain all the programing information so that i dont have to write the entire thing for each tree that will be choped down.

chop down tree =
x = 0
while turtle.detectUp do
turtle.digUp()
turtle.Up
x = x+1
end

while not turtle.detectUp() and x > 0 do
turtle.down()
x = x-1
end


if this makes any seance and you can help me, i would be verry happy
cant_delete_account #2
Posted 01 September 2012 - 06:07 PM
Use functions, here you go:

function chop()
x = 0
while turtle.detectUp() do
turtle.digUp()
turtle.up()
x = x+1
end
while not turtle.detectUp() and x > 0 do
turtle.down()
x = x-1
end
end
chop()
-- other stuff, just write chop() to run the code