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

Assistance in using functions and if-else statements

Started by xanderz221, 18 January 2014 - 01:35 PM
xanderz221 #1
Posted 18 January 2014 - 02:35 PM
Hi guys! This is my first time posting here and really my first time coding something a little more complicated.

this is a program written for a digging turtle that travels along and replaces whatever dirt block is below it with a stone brick.

I'm having trouble with it however:


function digbuild()
  while turtle.detectDown() do
	turtle.digDown()
	turtle.placeDown()
  end
end

function edges()
  if turtle.detectLeft()then
	turtle.turnLeft()
	turtle.back()
	turtle.place()
	turtle.digDown()
	turtle.turnLeft()
	turtle.placeDown()
	turtle.turnLeft()
  else
	while turtle.detectRight() do
	   turtle.turnRight()
	   turtle.back()
	   turtle.place()
	   turtle.digDown()
	   turtle.turnRight()
	   turtle.placeDown()
	   turtle.turnRight()
	end
  end
end

blocked = turtle.detect()

if blocked ~= true then
   turtle.forward
   digbuild()
else
   edges()
   turtle.forward()
   digbuild()
end


i thought it was pretty robust and functional, but i seem to be doing something wrong with the functions, or the if-else statement, because it gives me an error when i run the program. (I named it roadbuilder)

the error message is as follows:

bios:337: [string "roadbuilder"]:34: '=' expected

why do i need an = at line 34? this doesn't make sense to me

any help would be appreciated! Thanks
Lyqyd #2
Posted 18 January 2014 - 05:59 PM
You missed the parentheses on the turtle.forward.

There are no such functions as turtle.detectLeft() and turtle.detectRight().