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

[solved] :81: 'then' expected. then but there is a then

Started by zazarath, 05 June 2013 - 12:51 PM
zazarath #1
Posted 05 June 2013 - 02:51 PM
i trying to make a excavator that used an ender chest and records location not even nealry finished as you can see the error is on line 81
and for the life of me i cant see why

also any sugestions on making my code better more then welcome =P as i am still learning

o and yes i allready know my loc[4] heading set out is messed up =p i was half way thought testing when i relised


-- dig to bedrock
-- 5 by 5 whole

loc = {}
loc[1] = 0 -- X axsis  
loc[2] = 0 -- y axsis
loc[3] = 0 -- z axis
loc[4] = 0 -- facing  0 = +x, 1 = -y, 2 = -x, 3 = +y
-- ender chest in slot 1
function empty() -- emptys invetory into ender chest
turtle.select(1)
turtle.dig()
turtle.place()
for i = 1,16,1 do
  turtle.select(i)
  turtle.drop()
end
turtle.select(1)
turtle.dig()
end
function forward() -- forward with traking
while not turtle.forward() do
  turtle.dig()
end
while turtle.detectUp() do
  turtle.digUp()
  sleep(0.5)
end
turtle.digDown()
turtle.suck()
turtle.suckDown()
if loc[4] == 0 then
  loc[1] = loc[1] + 1
  else
  if loc[4] == 3 then
   loc[2] = loc[2] + 1
   else
   if loc[4] == 2 then
	loc[1] = loc[1] -1
	else
	if loc[4] == 1 then
	 loc[2] = loc[2] - 1
	end
   end
  end
end
end
-- turns recording heading
function left()
turtle.turnLeft()
if loc[4] == 3 then
  loc[4] = 0
  else
  loc[4] = loc[4] + 1
end
end
function right()
turtle.turnRight()
if loc[4] == 0 then
  loc[4] = 3
  else
  loc[4] =loc[4] - 1
end
end
-- turns
function down(downby) -- down with traking down(5) moves down 5 spaces
downk = 0
trydown = 0
while downby > downk do
  --print(downk, loc[3])
  while not turtle.down() do
   turtle.digDown()
   sleep(.5)
   if trydown = 4 then
	while turtle.attackDown() do
	 turtle.attackDown()
	 sleep(0.5)
	end
	else
	if turtle.detectDown() then
	 finished()
	end
	trydown = trydown + 1
   end
  end
  loc[3] = loc[3] - 1
  downk = downk + 1
end
end
function up(upby) -- up with traking up(5) moves up 5 spaces
downk = 0
while upby > downk do
  --print(downk, loc[3])
  while not turtle.up() do
   turtle.digUp()
   sleep(.5)
  end
  loc[3] = loc[3] + 1
  downk = downk + 1
end
end
function finished()
up(loc[3])

-- heading -x and moves to 0
while loc[4] ~= 2 do
  left()
end
while loc[2] ~= 0 do
  forward()
end

-- heading -y and moves to 0
while loc[4] ~=  1 do
  left()
end
while loc[1] ~= 0 do
  forward()
end

error("all finished")
end

-- testing
down(5)
forward()
forward()
farward()
right()
forward()
left()
forward()
finished()
Sammich Lord #2
Posted 05 June 2013 - 02:59 PM
You need == to compare. = is to define a variable.
GopherAtl #3
Posted 05 June 2013 - 03:03 PM
without actually looking at the code, you probably have = instead of ==.

:looks:

yawp, "if trydown = 4 then", ==, not =.
zazarath #4
Posted 05 June 2013 - 03:52 PM
o …… hmmmmm #palm face# thanks =)