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

bios:14: [string "Star"]:32: 'then' expected

Started by Raythornious, 18 July 2015 - 07:54 AM
Raythornious #1
Posted 18 July 2015 - 09:54 AM
The title refers to my original problem.
I wrote this to have a turtle mine in a + formation.
bios:14: [string "Star"]:32: 'then' expectedSolved
After I finish the initialization program stops and goes back to console.Solved

term.clear()
term.setCursorPos(1,1)
print("Dump chest goes in 16.")
print("Torch chest goes in 15.")
print("Fuel chest goes in 14.")
print("Torches go in 13.")
print("Put items in.")
print("Press any key to continue.")
os.pullEvent("key")
print("How far do I dig?")
x = read()
print("How far apart do torches go? Recommend:6")
y = read()
	
--Makes sure there isnt gravel or sand fallen down.
function digInfront()
	turtle.dig()
	while turtle.detect() do
		turtle.dig()
		sleep(0.1)
	end
end
	
--Makes sure there isnt gravel or sand fallen down.
function digAbove()
	turtle.digUp()
	sleep(0.5)
	while turtle.detectUp() do
		turtle.digUp()
		sleep(0.5)
	end
end
	
--Check/Place Torches
function torchManager()
	if turtle.getItemCount(13) < 1 then
		turtle.select(15)
		turtle.placeDown()
			turtle.select(13)
			turtle.suckDown()
			turtle.select(15)
		turtle.digDown()
		turtle.select(13)
		turtle.place()
		turtle.select(1)
	else
		turtle.select(13)
		turtle.place()
		turtle.select(1)
	end
end
	
--Places chest in last slot and drops items from slots 1-13 into chest, picks up chest.
function clearInv()
	turtle.select(16)
	turtle.place()
		for i = 1,12 do
			turtle.select(i)
			turtle.drop()
		end
		turtle.select(16)
	turtle.dig()
	turtle.select(1)
	end
	
--Checks for full inventory if full checks to see if it can place chest if it can then does clearInv().
function invMngr()
	turtle.getItemCount(12)
	if turtle.getItemCount(12) >= 1 then
		clearInv()
	end
end
	
--Does invMngr if facing forward.
function invMngrFront()
	turtle.getItemCount(12)
	if turtle.getItemCount(12) >= 1 then
		turtle.turnRight()
		turtle.turnRight()
		invMngr()
		turtle.turnRight()
		turtle.turnRight()
	end
end
	
--Does invMngr if facing right.
	function invMngrRight()
	turtle.getItemCount(12)
	if turtle.getItemCount(12) >= 1 then
		turtle.turnRight()
		invMngr()
		turtle.turnLeft()
	end
end
	
--Does invMngr if facing left.
	function invMngrLeft()
	turtle.getItemCount(12)
	if turtle.getItemCount(12) >= 1 then
		turtle.turnLeft()
		invMngr()
		turtle.turnRight()
	end
end
	
--Clears inventory takes a stack of fuel from fuel chest and refuels with it.
function fuelMngr()
	if turtle.getFuelLevel() == 0 then
		clearInv()
		turtle.select(14)
		turtle.place()
		turtle.select(1)
		turtle.suck()
		turtle.refuel()
		turtle.select(14)
		turtle.dig()
		turtle.select(1)
	end
end
	
--Digs a cross formation
function Digg()
	digInfront()
		invMngrFront()
	digAbove()
		invMngrFront()
	turtle.digDown()
		invMngrFront()
	turtle.turnRight()
	digInfront()
		invMngrRight()
	turtle.turnRight()
	turtle.turnRight()
	digInfront()
		invMngrLeft()
	t = t + 1 --Further tracks distance for torch placement.
		 if t >= y + 0 then --Checks if it places torches or nah.
		torchManager()
		t = t - y
	end
	turtle.turnRight() --Faces forward.
	m = m + 1 --Tracks force inventory clear
	if m >= 16 then
		clearInv()
		m = 0
	end
	fuelMngr()
	turtle.forward()
end

--For starting torch.
m = 0 --Defines the force inventory clear variable.
digInfront()
digAbove()
turtle.digDown()
turtle.turnRight()
digInfront()
turtle.turnRight()
turtle.turnRight()
digInfront()
turtle.select(13)
turtle.place()
turtle.select(1)
turtle.turnRight()
turtle.forward()
x = x - 1 --To count it as a dug layer for how far turtle goes.
m = m + 1 --To count for force inventory clear

--Time to make it run the cross digger.
t = 0			 --Tracks distance for torch placement.
for i = 1,x do	--Tracks how far turtle goes.
	Digg()
end
Any help/criticism is appreciated.

Edit1:Realized I made Digg a function and never called it.
Edit2:Updated code
Still open to criticism.
Edited on 18 July 2015 - 11:54 AM
Waitdev_ #2
Posted 18 July 2015 - 10:24 AM
your doing:

if turtle.getFuelLevel = 0 then
it should be:

if turtle.getFuelLevel==0 then
or:

if turtle.getFuelLevel == 0 then
and that should work.
believe me, i've got it before.
Raythornious #3
Posted 18 July 2015 - 11:09 AM
Thanks! That fixed my fuel check.