Jump to content




Assistance in using functions and if-else statements

turtle

1 reply to this topic

#1 xanderz221

  • New Members
  • 1 posts

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

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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().





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users