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.

 


 

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

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

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

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
On 10/22/2017 at 5:01 AM, HeyImJamie said:

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...