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

[Lua][Error]

Started by IceCrasher, 17 October 2012 - 08:18 PM
IceCrasher #1
Posted 17 October 2012 - 10:18 PM
Hi guys, please help me…

first, skyside is a programm which defines direct (1, 2, 3 or 4)

i get the following error message, but i have there a then :/

biox:328: [string "goto"]:110: 'then' expected

here is my programm on pastebin:
http://pastebin.com/XghJapgd

and here in the forum as you can see :P/>/>


-- for direct --> north=1, east=2, south=3, west=4
local ox, oy, oz = nil, nil, nil
local endx, endy, endz = nil, nil, nil
local stuck = 0

function getpos()
   rednet.open("right")
   cx, cy, cz = gps.locate(1)
end
getpos()

print("Wohin solls gehen?")
write("x: ")
nx = read()
write("y: ")
ny = read()
write("z: ")
nz = read()
write("In welche Richtung gucken (1-4)?")
ndirect = read()
function directto(x)
   while ndirect ~= direct do
	  turtle.turnRight()
	  if direct ~= 4 then
		 direct = direct + 1
	  else
		 direct = 1
	  end
   end  
  
function gox1()
   if cx < nx then
	  directto(1)  
	  if turtle.forward() then
		 cx = cx - 1
		 gox1()
	  else
		 gox3()
	  end
   end
end
		
function gox3()
   if cx > nx then
	  directto(3)
	  if turtle.forward() then
		 cx = cx +1
		 gox3()
	  else
		 goz2()
	  end
   end
end
function goz2()
   if cz < nz then
	  directto(2)
	  if turtle.forward() then
		 cz = cz + 1
		 goz2()
	  else
		 goz4()
	  end
   end
end
function goz4()
   if cz > nz then
	  directto(4)
	  if turtle.forward() then
		 cz = cz - 1
		 goz4()
	  else
		 goyu()
	  end
   end
end
function goyu()
   if cy < ny then
	  if turtle.up() then
		 cy = cy + 1
		 goyu()
	  else
		 goyd()
	  end
   end
end
function goyd()
   if cy > ny then
	  if turtle.down() then
		 cy = cy -1
		 goyd()
	  else
		 chegfuel()
	  end
   end
end
function chegfuel()
   if turtle.getFuelLevel > 0 and stuck = 0 then
	  if turtle.up() then
		 gox1()
	  elseif stuck < 1
		 stuck = 1
		 os.sleep(5)
		 gox1()
	  end
   else
	  if turtle.getFuelLevel = 0 then
		 print("I need more fuel!")
		 while turtle.getFuelLevel = 0 do
			os.sleep(5)
			turtle.refuel()
		 end
		 gox1()
	  else
		 print("Help my I'm stuck!")
		 print("Shut down the programm.")
	  end
   end	
end	
  
					
if not nx then
   nx = cx
end
if not ny then
   ny = cx
end
if not nz then
   nz = cz
end
shell.run("skyside")
if direct ~= nil then
   gox1()
   getpos()
   gox1()
end

thanks
jag #2
Posted 17 October 2012 - 10:31 PM
Well at line 110 you did a small typo:
if turtle.getFuelLevel > 0 and stuck = 0 then
It got stuck = 0, but it should be stuck == 0:
if turtle.getFuelLevel > 0 and stuck == 0 then

EDIT: And at line 119 you did it again:
if turtle.getFuelLevel = 0 then
Should be ==, not =
if turtle.getFuelLevel == 0 then

EDIT 2: And also, at line 29 you give your function directto() the variable x.
But I can't see a use of the x, so maybe it's unnecessary?

EDIT 3: At the top, you define your variables.
local ox, oy, oz = nil, nil, nil
local endx, endy, endz = nil, nil, nil
local stuck = 0
I might be wrong about this, but I think that when you define a variable with multiple "inputs/incomes/values" you only need to define the "value" once, as followed:
local ox, oy, oz = nil
local endx, endy, endz = nil
local stuck = 0
And plus, when you define a variable but you dont give it a value, it will automatically get assigned the value nil.
local ox, oy, oz
local endx, endy, endz
local stuck = 0
remiX #3
Posted 18 October 2012 - 05:47 AM
As jag said, you need two = signs because you are comparing two variables. You will only use one = sign when you are assigning a variable.
IceCrasher #4
Posted 29 October 2012 - 09:03 PM
thank you guys, but it isnt working at all, i think i'll rewrite the hole programm. if i start it now the turtle turns twice and then goes as far as it can :/