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

Program is messing up

Started by The_Awe35, 15 April 2013 - 07:23 AM
The_Awe35 #1
Posted 15 April 2013 - 09:23 AM
I have been working on a automatic tree Farming program. It is supposed to be fully integrated with gps so that it can find its place in the code from startup. It was working well, until I added the startup program. Once I did, it started messing up. I got rid of the startup, then closed and reopened minecraft. And when I try it now it errors : treeFarm:38: attempt to compsre __lt on nil and nil

I don't remember changing something in the code, but I obviously did. I can't figure out what I did, however. I have below the function that errors (also 2 others that it uses inside of it). It is the orient function. upon startup, it is supposed to check its coords, move, and based on the difference, figure out what direction it is facing.



function forward()
  while not turtle.forward() do
  turtle.dig()
  end
end

function getPos()
x,y,z = gps.locate()
end
 
function orient()
getPos()
xx = x
zz = z
forward()
getPos() 
 
  if zz > z then   -- line 38
  direction = "north"
  elseif zz < z then
  direction = "south"
  elseif xx > x then
  direction = "west"
  elseif xx < x then
  direction = "east"
  end

print(direction)
os.sleep(1)
turtle.back()
end

The full code is here: http://pastebin.com/9MTQE1xn

Note: There is probably some "junk" code or something that won't work in the full code, because I was doing some tuning up when this happened, so not all of the code has been tested to work.
SuicidalSTDz #2
Posted 15 April 2013 - 09:27 AM
Do you have a gps tower set up? If you don't then x,y,z = gps.locate() will never return any values. They will be nil, hence why zz and z are uncomparable.
The_Awe35 #3
Posted 15 April 2013 - 09:34 AM
No I do. It was working before. Had it run through the entire program before. No problems. Now, nothing. :(/>
The_Awe35 #4
Posted 15 April 2013 - 09:38 AM
WAIT WAIT WAIT!! I just realized that I am a giant idot. The gps cluster is fairly far away, and it was raining when I tried it. I forgot that the rednet range was decreased. "sigh"..I am an idot. Thanks anyway.
SuicidalSTDz #5
Posted 15 April 2013 - 09:40 AM
EDIT: Lol, ok. ^_^/> No problem