October 21, 20178 yr 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. Spoiler 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, 20178 yr by Jammer
October 21, 20178 yr 2 minutes ago, Jammer said: It's in Al Kharid 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, 20178 yr by Muffins
October 21, 20178 yr 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.
October 21, 20178 yr Author 1 hour ago, 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. 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, 20178 yr by Jammer
October 21, 20178 yr 1 hour ago, 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? https://en.wikibooks.org/wiki/Java_Programming/Preventing_NullPointerException
September 20, 20196 yr On 10/22/2017 at 5:01 AM, HeyImJamie said: https://en.wikibooks.org/wiki/Java_Programming/Preventing_NullPointerException 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 }
Create an account or sign in to comment