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

Program will not run - cant find what i think is a simple error

Started by TyCamden, 14 October 2012 - 08:56 PM
TyCamden #1
Posted 14 October 2012 - 10:56 PM
Sit the turtle down on a layer in front of a hole with a clearly defined edge, and this turtle should fill it.

But it won't run.

ERROR is:

bios:206: [string "fillarea"]:42:'then' expected

I looked at all of my IF statements, and they all seem to have a THEN with them, so I do not see the problem, Perhaps your keen eyes or mind will see it?


--[[ Program name : fillarea
	   Put this program in front of an unfilled hole in the ground
		 (with a defined edge on the layer the turtle is sitting on),
		 it should fill it with dirt then return to starting position.
	  --]]
--[[ Be sure the turtles has the following items
	  in the correct slots...
	    slot 13 has 64 coal/charcoal
	    other slots (at least 1) has filler (dirt/etc)
	  --]]
function refuel()
  fuellvl = turtle.getFuelLevel()
  if fuellvl<100 then
    amtchar = turtle.getItemCount(13)
    if amtchar > 1 then
	  turtle.select(13)
	  turtle.refuel(2)
	  turtle.select(1)
    else
	  if amtchar > 0 then
	    turtle.select(13)
	    turtle.refuel(1)
	    turtle.select(1)
	  end
    end
  end
end
function fillerCheck()
  fillerFlag = 0
  for X = 1,16 do
    turtle.select(X)
    if fillSlot == 13 then
	  fillSlot = 14
    end
    if turtle.getItemCount(X) > 0 then
	  fillerFlag = 1
    end
  end
  if fillerFlag = 0 then
    print "Out of Filler"
  end
end
function moveLeft()
  turtle.turnLeft()
  turtle.forward()
  turtle.turnRight()
  colModifier = colModifier - 1
end
function moveRight()
  turtle.turnLeft()
  turtle.forward()
  turtle.turnRight()
  colModifier = colModifier + 1
end
function moveForward()
  turtle.forward()
  rowModifier = rowModifier + 1
end
function moveBack()
  turtle.back()
  rowModifier = rowModifier - 1
end
function moveSide()
  if lookingLeft = 1 then
    moveLeft()
  else
    moveRight()
  end
end
function moveRecenter()
  while colModifier < 0 do
   moveRight()
  end
  while colModifier > 0 do
   moveLeft()
  end
end
function moveRecenterRow()
  while rowModifier < 0 do
    moveForward()
  end
  while rowModifier > 0 do
    moveBack()
  end
end
function fillHole()
  --[[ move down as far as it can --]]
  while not turtle.detectDown() do
    refuel()
    turtle.down()
    downMoves = downMoves + 1
  end
  --[[ move up and fill --]]
  while downMoves > 0 do
    refuel()
    turtle.up()
    fillerCheck()
    if fillerFlag = 1 then
	  while not turtle.placeDown() do
	    fillSlot = fillSlot + 1
	    if fillSlot == 13 then
		  fillSlot = 14
	    end
	    turtle.select(fillSlot)
	  end
	  turtle.placeDown()
    end
    downMoves = downMoves - 1
  end
  recentFillCol = 1
  recentFillRow = 1
end
--[[ set numeric var's --]]
  fuellvl = 0
  amtchar = 0
  fillerFlag = 0
  downMoves = 0
  X = 0
  fillSlot = 1
  rowModifier = 0
  colModifier = 0
  searchOver = 0
  lookingLeft = 1
  recentFillCol = 0
  recentFillRow = 0
--[[ move forward one --]]
  refuel()
  turtle.forward()
  rowModifier = rowModifier + 1
while searchOver = 0 and fillerFlag <> 0 do
  if not turtle.detectDown() then
    fillHole()
    moveSide()
  else
    --[[ no hole directly under --]]
    if recentFillCol = 1 then
	  --[[ there is no hole under AND the spot on the side WAS filled as well --]]
	  moveSide()
    else
	  --[[ there is no hole under AND the spot on the side was NOT filled as well --]]
	  if lookingLeft = 1 then
	    moveRecenter()
	    lookingLeft = 2
	    recentFillCol = 1 --[[ NOT SURE IF THIS IS NECESSARY --]]
	  else
	    moveRecenter()
	    if recentFillRow = 1 then
		  moveForward()
		  lookingLeft = 1
		  recentFillRow = 0
	    else
		  --[[ you are done with the filling of the hole --]]
		  searchOver = 1
	    end
	  end
    end
    recentFill = 0
  end
end
moveRecenter()
moveRecenterRow()
Doyle3694 #2
Posted 14 October 2012 - 10:58 PM

if fillerFlag = 0 then
1 to little ='s
PixelToast #3
Posted 14 October 2012 - 11:33 PM
common mistake, but you made it ALOT with this code
check through it and replace ='s with == in if statements
TyCamden #4
Posted 15 October 2012 - 02:25 PM
I fixed all of the instances where a single should be a double equals sign. Thanks for picking that up.

The last WHILE statement in the program looks like this: "while searchOver = 0 and fillerFlag <> 0 do" …

When I have a single-equals in the WHILE statement I get this error:

bios:206: [string "fillarea"]:144:'do' expected

and When I have a double-equals I get …

bios:206: [string "fillarea"]:144: unexpected symbol

One of these is correct, but either way - there is still something wrong with the program.

If you can help that would be great. Here is the full revised code:


--[[ Program name : fillarea
	   Put this program in front of an unfilled hole in the ground
		 (with a defined edge on the layer the turtle is sitting on),
		 it should fill it with dirt then return to starting position.
	  --]]
--[[ Be sure the turtles has the following items
	  in the correct slots...
	    slot 13 has 64 coal/charcoal
	    other slots (at least 1) has filler (dirt/etc)
	  --]]
function refuel()
  fuellvl = turtle.getFuelLevel()
  if fuellvl<100 then
    amtchar = turtle.getItemCount(13)
    if amtchar > 1 then
	  turtle.select(13)
	  turtle.refuel(2)
	  turtle.select(1)
    else
	  if amtchar > 0 then
	    turtle.select(13)
	    turtle.refuel(1)
	    turtle.select(1)
	  end
    end
  end
end
function fillerCheck()
  fillerFlag = 0
  for X = 1,16 do
    turtle.select(X)
    if fillSlot == 13 then
	  fillSlot = 14
    end
    if turtle.getItemCount(X) > 0 then
	  fillerFlag = 1
    end
  end
  if fillerFlag == 0 then
    print "Out of Filler"
  end
end
function moveLeft()
  turtle.turnLeft()
  turtle.forward()
  turtle.turnRight()
  colModifier = colModifier - 1
end
function moveRight()
  turtle.turnLeft()
  turtle.forward()
  turtle.turnRight()
  colModifier = colModifier + 1
end
function moveForward()
  turtle.forward()
  rowModifier = rowModifier + 1
end
function moveBack()
  turtle.back()
  rowModifier = rowModifier - 1
end
function moveSide()
  if lookingLeft == 1 then
    moveLeft()
  else
    moveRight()
  end
end
function moveRecenter()
  while colModifier < 0 do
   moveRight()
  end
  while colModifier > 0 do
   moveLeft()
  end
end
function moveRecenterRow()
  while rowModifier < 0 do
    moveForward()
  end
  while rowModifier > 0 do
    moveBack()
  end
end
function fillHole()
  --[[ move down as far as it can --]]
  while not turtle.detectDown() do
    refuel()
    turtle.down()
    downMoves = downMoves + 1
  end
  --[[ move up and fill --]]
  while downMoves > 0 do
    refuel()
    turtle.up()
    fillerCheck()
    if fillerFlag == 1 then
	  while not turtle.placeDown() do
	    fillSlot = fillSlot + 1
	    if fillSlot == 13 then
		  fillSlot = 14
	    end
	    turtle.select(fillSlot)
	  end
	  turtle.placeDown()
    end
    downMoves = downMoves - 1
  end
  recentFillCol = 1
  recentFillRow = 1
end
--[[ set numeric var's --]]
  fuellvl = 0
  amtchar = 0
  fillerFlag = 0
  downMoves = 0
  X = 0
  fillSlot = 1
  rowModifier = 0
  colModifier = 0
  searchOver = 0
  lookingLeft = 1
  recentFillCol = 0
  recentFillRow = 0
--[[ move forward one --]]
  refuel()
  turtle.forward()
  rowModifier = rowModifier + 1
while searchOver == 0 and fillerFlag <> 0 do
  if not turtle.detectDown() then
    fillHole()
    moveSide()
  else
    --[[ no hole directly under --]]
    if recentFillCol == 1 then
	  --[[ there is no hole under AND the spot on the side WAS filled as well --]]
	  moveSide()
    else
	  --[[ there is no hole under AND the spot on the side was NOT filled as well --]]
	  if lookingLeft == 1 then
	    moveRecenter()
	    lookingLeft = 2
	    recentFillCol = 1 --[[ NOT SURE IF THIS IS NECESSARY --]]
	  else
	    moveRecenter()
	    if recentFillRow == 1 then
		  moveForward()
		  lookingLeft = 1
		  recentFillRow = 0
	    else
		  --[[ you are done with the filling of the hole --]]
		  searchOver = 1
	    end
	  end
    end
    recentFill = 0
  end
end
moveRecenter()
moveRecenterRow()
PixelToast #5
Posted 15 October 2012 - 02:30 PM
<> is not a valid comparator, what are you trying to do?
remiX #6
Posted 15 October 2012 - 02:32 PM
<> lol..
If something is smaller than and bigger than 0. I don't even.
GopherAtl #7
Posted 15 October 2012 - 02:32 PM
Not-equal in lua is ~=, not <>
TyCamden #8
Posted 15 October 2012 - 05:16 PM
Thanks guyz. It runs now :D/>/>

I will post a new Topic for the logic problem it is having… but fixing these bugs helped a lot !
TyCamden #9
Posted 15 October 2012 - 08:14 PM
Here is the new topic that I need help with…

http://www.computercraft.info/forums2/index.php?/topic/5080-turtle-fill-hole-program-logic-problem/