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

Tree Cutting Program (basic) Asking for end

Started by sleawnis, 08 June 2013 - 01:51 PM
sleawnis #1
Posted 08 June 2013 - 03:51 PM
Im pretty sure i have messed up somewere…

print("Stating...")
local function pos()
turtle.dig()
turtle.forward()
end

local function tree()
while turtle.detectUp() == false do
turtle.digUp()
turtle.up()
end

local function down()
while turtle.detectDown() == false do
turtle.down()
end

local function between()
while turtle.detect() == false do
turtle.forward()
end

for x = 1, 5 do
tree()
descend()
between()
pos()
end

and my error is
 bios:338: [string "chop"]:28: 'end' expected (to close 'function' at mine 18) 

i cant see where ive gone wrong…
Engineer #2
Posted 08 June 2013 - 04:03 PM
You should close the while-loops too:
Spoiler

print("Stating...")
local function pos()
	turtle.dig()
	turtle.forward()
end

local function tree()
	while turtle.detectUp() == false do
		turtle.digUp()
		turtle.up()
	end
--Missing end

local function down()
	while turtle.detectDown() == false do
		turtle.down()
	end
--Missing end

local function between()
	while turtle.detect() == false do
		turtle.forward()
	end
--Missing end

for x = 1, 5 do
	tree()
	descend()
	between()
	pos()
end

Also, there is no need for so many functions, because you only call them once..

for x = 1, 5 do
	while turtle.detectUp() == false do
		turtle.digUp()
		turtle.up()
	end
	while turtle.detectDown() == false do
		turtle.down()
	end
	while turtle.detect() == false do
		turtle.forward()
	end
	turtle.dig()
	turtle.forward()
end
Edited on 08 June 2013 - 02:05 PM
sleawnis #3
Posted 08 June 2013 - 04:04 PM
Thanks xD i honestly dont know how i missed them xD