Jump to content

Problem with cooking


Jammer

Recommended Posts

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

 

Edited by Jammer
Link to comment
Share on other sites

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

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

  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

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
  On 10/21/2017 at 11:31 PM, HeyImJamie said:
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
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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