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

Java exception thrown

Started by java is dumb, 16 April 2015 - 06:41 PM
java is dumb #1
Posted 16 April 2015 - 08:41 PM
Hi, I'm new to computercraft but not new to programming.
My code is here: http://pastebin.com/v2pUQRpX

local sensor = peripheral.wrap("right")
local chatbox = peripheral.wrap("left")
while true do
  local allPlayers = sensor.getNearbyPlayers(300)
  local string = "!!! INTRUDER ALERT !!! - "

  for key, var in pairs(allPlayers) do
    string = string .. var['player']
  end
  if string ~= "!!! INTRUDER ALERT !!! - " then
    chatbox.tell("Notch", string)
  end
  sleep(1)
end
I'm trying to check if players are around, then tell me when it finds people.
When I run the program it says "java exception thrown" (Yes the peripherals are in the right place).


What's going on here and how do I fix it? Thanks.
Bomb Bloke #2
Posted 17 April 2015 - 12:00 AM
An error is occurring within the Java code that makes up the Lua environment. Most of the time scripters encounter this problem when they misuse a peripheral (many peripheral coders don't bother to check input data and generate proper Lua-based errors if it's not sanitised). In this case, I suspect this is your problem - what mod are you getting your sensor from, and do you perhaps need to update it…?