Jump to content

Null check


jua1

Recommended Posts

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
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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")

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

yea sorry i spelt it correctly in the script

 I think im going to do it a different way because this is not working it seems that the null check doesnt work for this object.

If you would like me to teamview you to sort the issue I would be more than happy. Just pm me your credentials if so ^_^

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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