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

[Lua][Error] if turtle.detect then

Started by IceCrasher, 02 October 2012 - 08:11 PM
IceCrasher #1
Posted 02 October 2012 - 10:11 PM
Hi guys, I get the following error message:
bios:328: [strint "startup"]:30: '='
expected

Here is my programm:

local fuellevel = 0
local cx, cy, cz = 0, 0, 0
local nx, ny, nz = 0, 0, 0
direct = 0
rednet.open("right")
cx, cy, cz = gps.locate(1)
if x and y and z then
   print(x..y..z)
else
  print("Couldn't get position")
end
function doit()
fuellevel = turtle.getFuelLevel()
if fuellevel < 0 then
   print("Please put fuel in slot1.")
end
while fuellevel < 0 do
   turtle.refuel()
end
print("Thank you.")
finddirect1
  if not turtle.detect() then
	 print("I need space in front of me!")
	 while turtle.detect do
		os.sleep(1)
		return
	 end
	 return
  else
	 finddirect2
  end
end
finddirect2
   nx, ny, nz = gps.locate(1)
   if nx < ox then
	  direct = 1
   end
   if nx >  ox then
	  direct = 3
   end
   if nz < oz then
	  direct = 4
   end
   if nz > oz then
	  direct = 2
   end
end  
finddirect1()

Please help me…
Cranium #2
Posted 02 October 2012 - 10:23 PM
Is finddirect a function or a variable? If you are calling tot he function, first move it up above where it's called, and define it by using function finddirect(). That way, lua knows it's a function. YOu would also want to call back to it by using fiddirect() as well, not finddirect.