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

Turtle wont run my program correctly

Started by gunner5209, 07 April 2016 - 10:54 PM
gunner5209 #1
Posted 08 April 2016 - 12:54 AM
Ok so I tried running my program so that it will mine a 3x3 tunnel for me but it wont run. Whenever I type mine in the shell so that it will start it doesn't give any errors but the turtle just sits there.


function up()
turtle.up()
end
function down()
turtle.down()
end
function f()
turtle.forward()
end
  function b()
turtle.back()
end

function r()
turtle.turnRight()
end

function l()
turtle.turnLeft()
end

function du()
turtle.dig()
end

function dd()
turtle.digDown()
end

function df()
turtle.dig()
endfunction checkFuel()
if turtle.getFuelLevel() <= 10 then
  for i=1, 16 do
   turtle.select(i)
   turtle.refuel(i)
end
end
  checkFuel()
write("How many blocks: ")
r = read()
for i=1,r do
df()
f()
r()
df()
f()
df()
du()
up()
l()
l()
df()
f()
df()
du()
up()
r()
r()
df()
f()
df()
down()
down()
l()
l()
f()
r()
checkFuel()
end

for i=1,r do
turtle.back()
end
turtle.turnRight()
for i=1,16 do
turtle.select(i)
turtle.transferTo(i)
end
end
KingofGamesYami #2
Posted 08 April 2016 - 01:39 AM
The entire last portion of your program is in the checkFuel function. Moving it out will cause it to be executed.
gunner5209 #3
Posted 08 April 2016 - 01:52 AM
The entire last portion of your program is in the checkFuel function. Moving it out will cause it to be executed.

I removed it from the bottom and it still isn't running did you mean to remove the function in it entirety?
Bomb Bloke #4
Posted 08 April 2016 - 03:58 AM
No, he means you've put code inside the checkFuel() function that you intended to put under it. Correcting your indentation to reflect how you've actually written things should help make this clear to you:

Spoiler
function up()
	turtle.up()
end

function down()
	turtle.down()
end

function f()
	turtle.forward()
end

function b()
	turtle.back()
end

function r()
	turtle.turnRight()
end

function l()
	turtle.turnLeft()
end

function du()
	turtle.dig()
end

function dd()
	turtle.digDown()
end

function df()
	turtle.dig()
end

function checkFuel()
	if turtle.getFuelLevel() <= 10 then
		for i=1, 16 do
			turtle.select(i)
			turtle.refuel(i)
		end
	end
	
	checkFuel()
	write("How many blocks: ")
	r = read()
	
	for i=1,r do
		df()
		f()
		r()
		df()
		f()
		df()
		du()
		up()
		l()
		l()
		df()
		f()
		df()
		du()
		up()
		r()
		r()
		df()
		f()
		df()
		down()
		down()
		l()
		l()
		f()
		r()
		checkFuel()
	end

	for i=1,r do
		turtle.back()
	end

	turtle.turnRight()
	for i=1,16 do
		turtle.select(i)
		turtle.transferTo(i)
	end
end

You just need to move an "end".
gunner5209 #5
Posted 08 April 2016 - 04:26 AM
No, he means you've put code inside the checkFuel() function that you intended to put under it. Correcting your indentation to reflect how you've actually written things should help make this clear to you:

Spoiler
function up()
	turtle.up()
end

function down()
	turtle.down()
end

function f()
	turtle.forward()
end

function b()
	turtle.back()
end

function r()
	turtle.turnRight()
end

function l()
	turtle.turnLeft()
end

function du()
	turtle.dig()
end

function dd()
	turtle.digDown()
end

function df()
	turtle.dig()
end

function checkFuel()
	if turtle.getFuelLevel() <= 10 then
		for i=1, 16 do
			turtle.select(i)
			turtle.refuel(i)
		end
	end
	
	checkFuel()
	write("How many blocks: ")
	r = read()
	
	for i=1,r do
		df()
		f()
		r()
		df()
		f()
		df()
		du()
		up()
		l()
		l()
		df()
		f()
		df()
		du()
		up()
		r()
		r()
		df()
		f()
		df()
		down()
		down()
		l()
		l()
		f()
		r()
		checkFuel()
	end

	for i=1,r do
		turtle.back()
	end

	turtle.turnRight()
	for i=1,16 do
		turtle.select(i)
		turtle.transferTo(i)
	end
end

You just need to move an "end".

Oh okay I'm seeing it now thanks for the help guys :)/>