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

java exception thrown ?

Started by Myribox, 08 July 2015 - 10:03 PM
Myribox #1
Posted 09 July 2015 - 12:03 AM
Hello everyone , i was tring to make a program with sensor and chatbox but i have the java exception thrown.
what does it mean?

Here is the program

sensor = peripheral.wrap("top")
s = peripheral.wrap("right")

while true do
for _, name in pairs(sensor.getPlayerByName()) do
  if name =="Myribox" then
   s.speak("Hello..name..")
  else
  s.speak("Out of here")
  end
sleep(0)
end
end


Sorry for my bad english
HPWebcamAble #2
Posted 09 July 2015 - 01:35 AM
Some peripherals don't check that the correct arguments are passed to their functions, causing Java Errors.
( In newer versions of CC, it tells you the error too - You are using CC 1.5 right? )

It is likely the 'sensor' or Chat Box causing the error. My best guess is this line:

for _, name in pairs(sensor.getPlayerByName()) do
I BELIEVE its 'getPlayersByName()' (add an 's' after 'Player')
But I can't be sure, since I have no idea which sensor you are using. Which mod is it from?

Though it could be the Chat Box. Try '.say' instead of '.speak'
( Is this the mod you are using for the Chat Box? )

Also, you have a few minor problems in your code:
Spoiler

sensor = peripheral.wrap("top")
chat = peripheral.wrap("right") --# 'chat' is more descriptive than 's'

while true do

  for _ , name in pairs( sensor.getPlayersByName() ) do

	if name == "Myribox" then
	  chat.say("Hello "..name) --# Slight problem with concatenation (Google it if you are confused)
	else
	  chat.say("Leave!") --# I guess this is the same as 'out of here'
	end

  end

  sleep(1) --# The sleep should be OUTSIDE of the for-loop, and doesn't need to be shorter than 1 second

end
Edited on 08 July 2015 - 11:37 PM
Myribox #3
Posted 09 July 2015 - 02:12 PM
Thanks for you help, but the code

for _ , name in pairs( sensor.getPlayerByName() ) do
is correct.
I stil have the same error

For the Sensor i'm using open perihperal
-OpenPeripheralAddons-1.7.10-0.3.1b
-OpenPeripheralCore-1.7.10-1.1.1
-OpenPeripheralIntegration-1.7.10-0.2.2

And for the Speaker its -Peripherals++-1.2.10

and CC its Comptercraft.1.73
Edited on 09 July 2015 - 02:04 PM
HPWebcamAble #4
Posted 09 July 2015 - 04:52 PM
Hm CC 1.73 should tell you the exact error, but it doesn't really matter.


According to this page, the Sensor's 'getPlayerByName()' function ALSO requires a name - It doesn't get the names of all players in range, rather info about a single player.
(Not passing the name could cause a Java error)

The function you are likely looking for is 'getPlayers()'
Edited on 09 July 2015 - 02:53 PM