Jump to content




[Lua][Error] if turtle.detect then


  • You cannot reply to this topic
10 replies to this topic

#1 IceCrasher

  • Members
  • 40 posts

Posted 07 October 2012 - 09:38 PM

hi guys, i get ever and ever the same error please help :D/>

bios:328: [string "skyside"]:30: '(' expected

here is the 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.")
function finddirect1
	   if 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
function 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()

thanks

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 07 October 2012 - 09:43 PM

Have you tried adding '()' to 'finddirect2' on line thirty, making it 'finddirect2()'?

#3 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 07 October 2012 - 09:44 PM

View PostLyqyd, on 07 October 2012 - 09:43 PM, said:

Have you tried adding '()' to 'finddirect2' on line thirty, making it 'finddirect2()'?

Same goes for finddirect1 (just saying to be sure :D/> )

#4 jag

  • Members
  • 533 posts
  • LocationStockholm, Sweden

Posted 07 October 2012 - 10:09 PM

And you forgot the () on line 30, at turtle.detect

#5 Pharap

  • Members
  • 816 posts
  • LocationEngland

Posted 08 October 2012 - 02:12 AM

View Postjag_e_nummer_ett, on 07 October 2012 - 10:09 PM, said:

And you forgot the () on line 30, at turtle.detect

If you're thinking that's line 30, you must be leaving at least about 6 lines of blank space.
Regardless, your point is valid.

View PostIceCrasher, on 07 October 2012 - 09:38 PM, said:

hi guys, i get ever and ever the same error please help :D/>

bios:328: [string "skyside"]:30: '(' expected

thanks

firstly, error message:

bios:328: <-- indicates one issue in bios
[string "skyside"] <-- indicates more data about that error
:30: <-- indicates line in your code causing the error
'(' expected <-- tells you the problem

secondly, reworked code, which should no longer error:

local fuellevel = 0
local cx, cy, cz = 0, 0, 0
local nx, ny, nz = 0, 0, 0
direct = 0 -- this might need to be local if it's not used outside the program
--try to declare functions before using them
function finddirect2()
   nx, ny, nz = gps.locate(1) --I think gps needs more args than this, but I could be wrong, it's been ages since I used GPS
   if nx < ox then
		  direct = 1
   elseif nx >  ox then -- else ifs save time and end statements
		  direct = 3
   elseif nz < oz then
		  direct = 4
   elseif nz > oz then
		  direct = 2
   end
end 

function finddirect1
		   if 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
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.")
end -- always end functions
--the main stuff:
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
finddirect1()

If there are any more issues, the forums are here

#6 IceCrasher

  • Members
  • 40 posts

Posted 08 October 2012 - 09:16 AM

so ok, thank you all and yay I'm a noob :D/>

so I fixed the programm but there is one little thingy that don't want to work ;)/>

when I run the programm it says:
772, 4, -284
skyside:48: attempt to compare nil with number

I really don't know why, because in line 8 it works :/


local fuellevel = 0
local cx, cy, cz = nil, nil, nil
local nx, ny, nz = nil, nil, nil
-- local  x,  y,  z = nil, nil, nil
direct = 0

rednet.open("right")
cx, cy, cz = gps.locate(3)

if cx and cy and cz then
   print(cx..", "..cy..", "..cz)
   doit()
   finddirect1()
   print(""..direct) 
else
  print("Couldn't get position")
end

function  doit()
   fuellevel = turtle.getFuelLevel()
   if fuellevel < 0 then
      print("Please put fuel in slot1.")
      while fuellevel < 0 do
         turtle.refuel()
         fuellevel = turtle.getFuelLevel()
         os.sleep(1)
         return
      end
      print("Thank you :D/>/>")
    end
end

function finddirect1()
   if turtle.detect() then
       print("I need space in front of me!")
       while turtle.detect do 
                os.sleep(1)
          return
       end
       return
    else
        turtle.forward()
        finddirect2() 
    end
end

function finddirect2()
   nx, ny, nz = gps.locate(3)
   if nx and ny and nz then
      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
end


#7 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 08 October 2012 - 09:38 AM

if nx<ox then

where are you getting ox from? it is nil because it has not been assigned a value, you cannot see if nil is bigger than a number

#8 Pharap

  • Members
  • 816 posts
  • LocationEngland

Posted 08 October 2012 - 09:47 AM

View PostIceCrasher, on 08 October 2012 - 09:16 AM, said:

so ok, thank you all and yay I'm a noob :D/>

so I fixed the programm but there is one little thingy that don't want to work ;)/>

when I run the programm it says:
772, 4, -284
skyside:48: attempt to compare nil with number

I really don't know why, because in line 8 it works :/


local fuellevel = 0
local cx, cy, cz = nil, nil, nil
local nx, ny, nz = nil, nil, nil
-- local  x,  y,  z = nil, nil, nil
direct = 0

rednet.open("right")
cx, cy, cz = gps.locate(3)

if cx and cy and cz then
   print(cx..", "..cy..", "..cz)
   doit()
   finddirect1()
   print(""..direct)
else
  print("Couldn't get position")
end

function  doit()
   fuellevel = turtle.getFuelLevel()
   if fuellevel < 0 then
	  print("Please put fuel in slot1.")
	  while fuellevel < 0 do
		 turtle.refuel()
		 fuellevel = turtle.getFuelLevel()
		 os.sleep(1)
		 return
	  end
	  print("Thank you :D/>/>")
	end
end

function finddirect1()
   if turtle.detect() then
	   print("I need space in front of me!")
	   while turtle.detect do
				os.sleep(1)
		  return
	   end
	   return
	else
		turtle.forward()
		finddirect2()
	end
end

function finddirect2()
   nx, ny, nz = gps.locate(3)
   if nx and ny and nz then
	  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
end

You are trying to compare nx and nz with the non-existant ox and oz. Basically you appear to be using variables that haven't been assigned.
That and it's possible gps can't do the location and is returning nil. You might want to test if values are nil after the gps.locate() and then if they are, get the code to try again a few times before aborting the script.

#9 IceCrasher

  • Members
  • 40 posts

Posted 08 October 2012 - 10:09 AM

thank you guys, know my first usefull programm is working xD

#10 Pharap

  • Members
  • 816 posts
  • LocationEngland

Posted 08 October 2012 - 10:18 AM

Glad to be of help. If you need any more help, be sure to ask the forums, we have nothing better to do.

#11 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 08 October 2012 - 10:33 AM

View PostPharap, on 08 October 2012 - 10:18 AM, said:

Glad to be of help. If you need any more help, be sure to ask the forums, we have nothing better to do.

lol speak for yourself :D/> I'm at work





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users