Jump to content

Null check


Recommended Posts

Posted (edited)

script keeps getting stuck on a if(closestObject(9345) != null)    the object is a bird snare and it is on the ground when it cycles through to the null check but it never gets passed. I've tried using closestNPC(), closestObjectForName(), ClosestNPCForName() all dont make it passed the null check.

	public void LaySnare() throws InterruptedException {
		Inventory Inven = client.getInventory();
		final RS2Object GroundSnare = closestObject(9345);
		final Entity player = client.getMyPlayer();
		if (player != null)
			if (HuntingGround.contains(player)) {
				if (Inven.contains(BirdSnareItem) == true) {
					Inven.interactWithName(BirdSnareItem, InteractSnare);
					sleep(10000);
					if(GroundSnare != null){
						log("logging snare position");
					snare = GroundSnare.getPosition();
					if(!Inven.contains(BirdSnareItem)){
						log(DetectState);
						StateHolder = 0;}
				 }
				}
			} else {
				walkExact(HuntingGround);
			}
	}
Edited by jua1
Posted

script keeps getting stuck on a if(closestObject(9345) != null)    the object is a bird snare and it is on the ground when it cycles through to the null check but it never gets passed. I've tried using closestNPC(), closestObjectForName(), ClosestNPCForName() all dont make it passed the null check.

 

do you want to pick it back up off the floor when it collapses?

Posted (edited)

nah after the null check i log its position so that you can run this with other people hunting in the same area and not try to pick up their snares, but the problem is the getPosition() requires a null check and i've also tried exist().

 

Edited by jua1
Posted (edited)

thats possible but when i place it on the ground i get no value for ground item. Worth trying though il try it right now.

Yea its not a ground item

First things first I think you need to be more clear as to what you're trying to do with the trap, bird traps have 4 states: 

  • Layed (Waiting for Bird to smoke) id  = 9345
  • Smoked (Failed to catch crimson) id = 9344
  • Caught (Caught the Crimson) id = 9373
  • Fell down (This is a  GroundItem now) id: 10006

With the ID you provided in the OP you are trying to do something with the "Layed" trap which doesn't really make sense but hope this gives some clarity:

 

I'll give you a snippet of what's in my Divinity Birds script which works perfectly:

RS2Object setTrap = closestObjectForId(9345);

if(setTrap != null){
  if(setTrap.isVisible()){
     setTrap.interact("Dismantle");
     sleep(random(700,1200));
  } else {
    client.moveCameraToEntity(setTrap);
  }
}
Edited by Divinity
  • Like 1
Posted

this is only a snippet of the code that is where its getting stuck. If i dont getPosition of the snare my script works perfectly. I need to log their positions though so you can run the script next to other bots or else its going to try to pick up other ppls snares. Im telling you guys I am only having problem with the null check for closestObjectForName("Bird Snare")

Posted

this is only a snippet of the code that is where its getting stuck. If i dont getPosition of the snare my script works perfectly. I need to log their positions though so you can run the script next to other bots or else its going to try to pick up other ppls snares. Im telling you guys I am only having problem with the null check for closestObjectForName("Bird Snare")

Ahhhh in that case you need to make sure it's spelt correctly... it's "Bird snare" with a small "s"

Posted

Just so you can get better:

  1. NEVER EVER EVER EVER EVERRRRRR check for a boolean value by doing "==" or anything of the sort
  2. Final variables should be all caps separated by _ characters for spaces
  3. Variables/methods should be camelCased (unless their final)
  4. Not sure if just how you copy/pasted but your brackets are all over the place
  5. What is the point of making those variables final

As for your question, try logging before that line what the ground snare is equal to.

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...