Jammer Posted October 21, 2017 Share Posted October 21, 2017 (edited) So I'm trying to make a simple cooking script that cooks in Al-kharid and everything is working smoothly except for one thing. The problem occurs when I'm trying to interact with the cook all widget. When the code looks like this the script presses on the fish and then on the range like five times before eventually pressing on cook all. I then tried to add an if statement to see if that would solve it: if(!cookAll.isVisible()) { getInventory().interact("Use", mat); range.interact("Use"); sleep(1000); } else { cookAll.interact("Cook"); sleep(1000); //I guess I could use a conditional sleep here but thats not the problem } But when I do this the client freezes. Reveal hidden contents package simplecooker; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.api.ui.RS2Widget; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; @ScriptManifest(author = "mex", info = "cooks in al kharid", logo = "df", name = "alkahrid cooker", version = 1.0) public class Everything extends Script { final Area COOKINGAREA = new Area(3272, 3182, 3274, 3179); final Area BANKINGAREA = new Area(3269, 3170, 3271, 3164); @Override public int onLoop() throws InterruptedException { RS2Object range = objects.closest("Range"); RS2Widget cookAll = getWidgets().get(270, 14); String mat; mat = "Raw trout"; if (getInventory().contains(mat)) { if (COOKINGAREA.contains(myPlayer())) { if (!myPlayer().isAnimating()) { if(!cookAll.isVisible()) { getInventory().interact("Use", mat); range.interact("Use"); } cookAll.interact("Cook"); sleep(2000); } { } } else { getWalking().webWalk(COOKINGAREA); } } else { getWalking().webWalk(BANKINGAREA); } if (BANKINGAREA.contains(myPlayer())) { if (getBank().isOpen()) { bank.depositAll(); sleep(2000); bank.withdraw(mat, 28); sleep(2000); } else { bank.open(); sleep(2000); } } return 100; } } Edited October 21, 2017 by Jammer Quote Link to comment Share on other sites More sharing options...
Muffins Posted October 21, 2017 Share Posted October 21, 2017 if its the lumby range it wont work Quote Link to comment Share on other sites More sharing options...
Jammer Posted October 21, 2017 Author Share Posted October 21, 2017 It's in Al Kharid Quote Link to comment Share on other sites More sharing options...
Muffins Posted October 21, 2017 Share Posted October 21, 2017 (edited) On 10/21/2017 at 9:12 PM, Jammer said: It's in Al Kharid Expand it should also be getObjects().getClosest("Range"); i believe edit: also the rest of your code is kinda well..... bad. might wanna brush up on java/osbot api before attempting again Edited October 21, 2017 by Muffins Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted October 21, 2017 Share Posted October 21, 2017 You're not null checking your widget, which is probably why the script freezes. I'd also look into using an alternative method to find your widget as using static IDs isn't the best practice when there's so many other ways to do it. Quote Link to comment Share on other sites More sharing options...
Jammer Posted October 21, 2017 Author Share Posted October 21, 2017 (edited) On 10/21/2017 at 9:14 PM, HeyImJamie said: You're not null checking your widget, which is probably why the script freezes. I'd also look into using an alternative method to find your widget as using static IDs isn't the best practice when there's so many other ways to do it. Expand Thanks got it to work at last, I was starting to go insane. RS2Widget cookAll = getWidgets().getWidgetContainingText("Cook"); Do you mean something like that? And btw, why doesn't isVisible work but checking if it's null does? Edited October 21, 2017 by Jammer Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted October 21, 2017 Share Posted October 21, 2017 On 10/21/2017 at 10:24 PM, Jammer said: Thanks got it to work at last, I was starting to go insane. RS2Widget cookAll = getWidgets().getWidgetContainingText("Cook"); Do you mean something like that? And btw, why doesn't isVisible work but checking if it's null does? Expand https://en.wikibooks.org/wiki/Java_Programming/Preventing_NullPointerException 1 Quote Link to comment Share on other sites More sharing options...
lingmaaki Posted September 20, 2019 Share Posted September 20, 2019 On 10/21/2017 at 11:31 PM, HeyImJamie said: https://en.wikibooks.org/wiki/Java_Programming/Preventing_NullPointerException Expand NullPointerExceptions are exceptions that occur when you try to use a reference that points to no location in memory (null) as though it were referencing an object. Calling a method on a null reference or trying to access a field of a null reference will trigger a NullPointerException. For example, String s = null; int len = s.length(); // NullPointerException because s is null So you should check if the variable is null before calling any method on it, for example: int len; if (s == null) { len = 0; } else { len = s.length(); // safe, s is never null when you get here } Quote Link to comment Share on other sites More sharing options...
dreameo Posted September 20, 2019 Share Posted September 20, 2019 And just like a NPE, this thread is dead, don't try to access it 1 1 Quote Link to comment Share on other sites More sharing options...