Joseph Posted June 12, 2013 Share Posted June 12, 2013 (edited) can someone explain to me this \/ catch try {...................} catch (interruptedException e) // TODO Auto-generated catch block e.printStackTrace(); } im trying to create a farming script, and on the onStart() i want it to do more then one action. But i don't fully understand the (catch............). do i only need one (Catch..........), or more then one, if my onStart() has more then one action. public void onStart(){ if (client.getInventory().contains(ectophial) && !EctoArea.contains(myPlayer())){ try { this.client.getInventory().interactWithId(ectophial, "Empty"); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (myPlayer().getAnimation()== 714) { while(myPlayer().getAnimation()== 714) { try { sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } state = State.WALKTOECTOHERB; } } } Edited June 12, 2013 by josedpay Link to comment Share on other sites More sharing options...
Link Posted June 12, 2013 Share Posted June 12, 2013 do i only need one (Catch..........), or more then one, if my onStart() has more then one action. You don't necessarily need it at all. Also, This !EctoArea.contains(myPlayer()) Should be this !client.getMyPlayer().isInArea(EctoArea)) Link to comment Share on other sites More sharing options...
Wizard Posted June 12, 2013 Share Posted June 12, 2013 Dont catch the exception, you should throw it, so in the method signature throw InterruptedException so it would be like public void onStart() throws InterruptedException { and remove the try and catch block. Link to comment Share on other sites More sharing options...
Joseph Posted June 12, 2013 Author Share Posted June 12, 2013 (edited) so it should look something like this then public void onStart() throws InterruptedException { if (client.getInventory().contains(ectophial) &&!client.getMyPlayer().isInArea(EctoArea)) { client.getInventory().interactWithId(ectophial, "Empty"); if (myPlayer().getAnimation()== 714) { while (myPlayer().getAnimation()== 714) { sleep(1000); } } state = State.WALKTOECTOHERB; } } i try this out then Eclipse is having a sissy fit, it say you remove the exception. Edited June 12, 2013 by josedpay Link to comment Share on other sites More sharing options...
Wizard Posted June 12, 2013 Share Posted June 12, 2013 (edited) What the error? when you hover over the red line what does it say? EDIT: nvm remove the throw thing, the onStart method in the Scrip class doesnt throw InterruptedException, I think you have to add the try and catch blocks again And what is try and catch basically is a code that try to preform the code between the try {} and if something unexcepted happened it catches the errors. Edited June 12, 2013 by Mithrandir Link to comment Share on other sites More sharing options...
Kati2 Posted June 12, 2013 Share Posted June 12, 2013 You don't necessarily need it at all. Also, This !EctoArea.contains(myPlayer()) Should be this !client.getMyPlayer().isInArea(EctoArea)) Easier to do !myPlayer().isinArea(EctoArea)) OT - Just throw InterruptedException Link to comment Share on other sites More sharing options...
Joseph Posted June 12, 2013 Author Share Posted June 12, 2013 What the error? when you hover over the red line what does it say? EDIT: nvm remove the throw thing, the onStart method in the Scrip class doesnt throw InterruptedException, I think you have to add the try and catch blocks again And what is try and catch basically is a code that try to preform the code between the try {} and if something unexcepted happened it catches the errors. public void onStart() { if (client.getInventory().contains(ectophial) &&!myPlayer().isInArea(EctoArea)) { try { client.getInventory().interactWithId(ectophial, "Empty"); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (myPlayer().getAnimation()== 714) { while (myPlayer().getAnimation()== 714) { try { sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } state = State.WALKTOECTOHERB; } } so then this (what i had in the beginning, with just a little tweaks ) Link to comment Share on other sites More sharing options...
Wizard Posted June 12, 2013 Share Posted June 12, 2013 public void onStart() { if (client.getInventory().contains(ectophial) &&!myPlayer().isInArea(EctoArea)) { try { client.getInventory().interactWithId(ectophial, "Empty"); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (myPlayer().getAnimation()== 714) { while (myPlayer().getAnimation()== 714) { try { sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } state = State.WALKTOECTOHERB; } } so then this (what i had in the beginning, with just a little tweaks ) public void onStart() { if (client.getInventory().contains(ectophial) &&!myPlayer().isInArea(EctoArea)) { client.getInventory().interactWithId(ectophial, "Empty"); if (myPlayer().getAnimation()== 714) { while (myPlayer().getAnimation()== 714) { try { sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } state = State.WALKTOECTOHERB; } } Link to comment Share on other sites More sharing options...
Joseph Posted June 12, 2013 Author Share Posted June 12, 2013 its telling me to put a try and catch method on client.getInventory().interactWithId(ectophial, "Empty"); Link to comment Share on other sites More sharing options...