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

[1.2.5][SSP] Computercraft Error: nil: vm error: java.lang.NullPointerException

Started by BigBlaster10, 08 September 2012 - 11:29 PM
BigBlaster10 #1
Posted 09 September 2012 - 01:29 AM
When i run my code:

print("How Long Do You Want The Branches?")
length = t
middle = 3
lengthStop = false
local length = read()
local length1 = length
local length2 = length
--print("How Many Branches Do You Want?")
--local branch = read()

while length ~= 0 do
   turtle.dig()
   sleep(0.4)
   if turtle.detect() then
   turtle.dig()
  
   else
	  turtle.forward()
	  turtle.digUp()
	  length = length-1 
	  --print(length)	 
  
  
	  end
   end

if length == 0 then
   if lengthStop == false then
   length = length -1
   turtle.turnRight()
   turtle.dig()
   sleep(0.4) 
   print(lengthStop)  
  
   while middle ~= 0 do		 
	  if middle ~= 0 and not turtle.detect() then --Buggy
		    turtle.forward()
	  turtle.digUp()
	  middle = middle - 1
   print(middle)
		 end
   while turtle.detect() and middle ~= 0 do
		    turtle.dig()
		 sleep(0.4)
  
	 
	  end 
	  if middle == 0 and lengthStop == false then
	  print(length)
   lengthStop = true
   middle = 3
	  turtle.forward()
	  turtle.turnRight()
		 length = length - 1	 
	 
  
	  end
	  end
   end  
end  
while length == -2 do
   if length2 ~= 0 then 
   turtle.dig()
   sleep(0.4)
   if turtle.detect() then
   turtle.dig()
  
   else
	  turtle.forward()
	  turtle.digUp()
	  length2 = length2-1 
	  print(length2)	 
  
  
	  end
   end
end
if turtle.detectDown then
turtle.placeDown()
end
if length2 == 0 then
end
It Gives The Mining Turtle The Error: nil: vm error: java.lang.NullPointerException
PixelToast #2
Posted 09 September 2012 - 11:59 PM
when does it error? has the turtle moved?
MysticT #3
Posted 10 September 2012 - 12:12 AM
Well, this is not a bug. Your code has some errors, the one that is probably causing the error is in this line:

local length = read()
[CODE]
read() returns a string, you want a number, so you should use tonumber(read()). All the comparisons after that will be wrong, since you compare to a number. What's probably happening is that one of the loops never end (because of the condition never being false), and you don't yield inside that loop, so it hangs the computer and throws that error.