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

nil: vm error: java.lang.NullPointerException

Started by Arkanoid, 09 September 2012 - 06:39 PM
Arkanoid #1
Posted 09 September 2012 - 08:39 PM
Okay so I guess this is probably a bug in the virtual machine, but I just want to know if there's anything I can do to work round it. I'm really new to programming and I'm trying to make a railway system where this is the junction controller. Not sure at all what's causing this.

Hey so I have a new problem, now I'm having trouble with the line


table.remove(track[1][1])

I can find the value of track[1][1], but I can't seem to remove it from the list. I don't know the exact error because computercraft is being weird on the server. Any ideas?


Never mind I fixed that one too, I guess the scarecrow had a brain all along lol




endloop = false
rednet.open("bottom")
tno=1
A1 ={}
A2 = {}
B1 = {}
B2 = {}
C = {}
D = {}

trains ={}

function newtrain(station)
if station == 4 then x = A1
elseif station == 7 then x = B1
elseif station == 9 then x = D
else print "invalid station"
end
print(x)

table.insert(x, trains[tno])
tno = tno+1
if #x == 1 then
  print "new train is next to junction"
  neworder(x)
end

end

function neworder(track)
rainbow = (rs.getBundledOutput("right"))
if track == A1 then wire = colors.red
elseif track == B1 then wire = colors.orange
elseif track == D then wire = colors.yellow
else print "invalid track"
end
print(rainbow)
wiretest = colors.test(rainbow, wire)
if wiretest == false then
  print "wire is off"
  if track[1][1] == "x" then
   rs.setBundledOutput("right", colors.combine(rainbow, wire))
  end
elseif wiretest == true then
  print "wire is on"
  if track[1][1] == "y" then
   rs.setBundledOutput("right", colors.subtract(rainbow, wire))
  end
end
table.remove(track[1][1])
end


function changeline(col, new, old)
if rs.testBundledInput("right", col) == true then
  table.insert(new)
  table.remove(old[1])
  neworder(old)
end
end

function statechange()
changeline(colors.green, A2, D)
changeline(colors.lightBlue, A2, A1)
changeline(colors.blue, B2, B1)
changeline(colors.purple, B2, D)
changeline(colors.black, C, B1)
changeline(colors.white, C, A1)
end

repeat
event, id, msg = os.pullEvent()
if event == "rednet_message" then
  trains[tno] = {msg}
  print(trains[1])
  newtrain(id)
elseif event == "redstone" then
  statechange()
end
until endloop == true
MysticT #2
Posted 09 September 2012 - 09:18 PM
You'r missing the brackets for the pullEvent call, so it never yields, making the computer hang and throw that error.
Arkanoid #3
Posted 09 September 2012 - 10:11 PM
Yup I actually figured that one out by myself but thanks! :D/>/>