Author Topic: World.getObject(id) issue  (Read 709 times)

Offline voronwe13

  • byte
  • *
  • Posts: 15
    • View Profile
World.getObject(id) issue
« on: September 10, 2014, 07:24:53 pm »
I'm having an issue where I need to check if a world has a specific object in it, or whether it has been removed from the world.   Essentially, I'm doing:
Code: [Select]
if(world.getObject(object.getID()) == null){
   world.addObject(object);
}

The problem I'm having is that instead of returning null, the app is erroring out with the following message:

java.lang.RuntimeException: [ 1410369008776 ] - ERROR: Can't retrieve object #6!


at the line where I call world.getObject(object.getID());

Am I doing something wrong?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11749
    • View Profile
    • http://www.jpct.net
Re: World.getObject(id) issue
« Reply #1 on: September 10, 2014, 07:54:20 pm »
No, that's the way it's supposed to behave if the object can't be found. You can wrap it in a try-catch or, which would be more performance friendly, change the Logger's on error behaviour at for that part of the code.

Offline voronwe13

  • byte
  • *
  • Posts: 15
    • View Profile
Re: World.getObject(id) issue
« Reply #2 on: September 10, 2014, 08:31:24 pm »
Okay, wasn't expecting that based on the documentation.  It works now that I've set the Logger appropriately at that section of code.   Thanks!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11749
    • View Profile
    • http://www.jpct.net
Re: World.getObject(id) issue
« Reply #3 on: September 10, 2014, 09:26:01 pm »
I see. The documentation is from a time where the default error behaviour was different. I'll update the docs, thanks for mentioning it.