scriptersteve Posted January 14, 2018 Share Posted January 14, 2018 Item strPot = getInventory().getItem("Strength potion(4)","Strength potion(3)","Strength potion(2)","Strength potion(1)"); The following line of code, causes my script to not even start even when i am not implementing it anywhere in the script just defining it at the beginning. TRying to use it in the following scenario:- if((getSkills().getDynamic(Skill.STRENGTH) - getSkills().getStatic(Skill.STRENGTH)) < pottingValue) { if(inventory.contains("Strength potion(4)","Strength potion(3)","Strength potion(2)","Strength potion(1)")){ strPot.interact("Drink"); } pottingValue = random(2,6); } Link to comment Share on other sites More sharing options...
Explv Posted January 14, 2018 Share Posted January 14, 2018 (edited) 45 minutes ago, scriptersteve said: Item strPot = getInventory().getItem("Strength potion(4)","Strength potion(3)","Strength potion(2)","Strength potion(1)"); The following line of code, causes my script to not even start even when i am not implementing it anywhere in the script just defining it at the beginning. TRying to use it in the following scenario:- if((getSkills().getDynamic(Skill.STRENGTH) - getSkills().getStatic(Skill.STRENGTH)) < pottingValue) { if(inventory.contains("Strength potion(4)","Strength potion(3)","Strength potion(2)","Strength potion(1)")){ strPot.interact("Drink"); } pottingValue = random(2,6); } I'm assuming that strPot is defined as a member variable. You can't do that, the API will not be setup yet. The order is as follows: Static variables are initialised Member variables are initialised Constructor is called API context is exchanged onStart() is called onLoop() is repeatedly called until script exit You are defining strPot as a member variable, if you look at the above list, you can see that it will be initialised before the API context is exchanged. This means that getInventory().getItem() will throw an NPE somewhere and your script will crash. It doesn't make sense to do it there anyway, as it will only get a strength potion from your inventory once. If you then consumed that strength potion, that Item would no longer exist and your script would fail. You need to call getInventory().getItem() every time you want to drink the potion. The code should be put inside of your if (inventory contains strength potion) check. Side note: You can make use of a Filter<Item> to reduce some code, for example: private final Filter<Item> strPotionFilter = item -> item.getName().startsWith("Strength potion("); public void someMethod() { Item strPotion = getInventory().getItem(strPotionFilter); if (strPotion != null) { strPotion.interact("Drink"); } } Edited January 14, 2018 by Explv 1 Link to comment Share on other sites More sharing options...
scriptersteve Posted January 14, 2018 Author Share Posted January 14, 2018 ok thanks and yes it was defined before my on start Link to comment Share on other sites More sharing options...
scriptersteve Posted January 14, 2018 Author Share Posted January 14, 2018 got it working now thanks alot Link to comment Share on other sites More sharing options...