Jump to content

Item isn't in inv


Recommended Posts

Posted
if (!getInventory().contains("Lobster pot")) {
            if (!getBank().open()) {
                getBank().open();
                if (getBank().contains("Lobster pot"))
                    getBank().getItem("Lobster pot");
                    System.out.println("Taken a lobster pot out of the bank to fish with.");
                while (!getBank().isOpen()) {
                    sleep(random(200, 300));
                    localWalker.walkPath(backFishing);
                }
                    return 2000;
                }
            }

I'm not sure why but this doesn't seem to work..

 

If my inv doesn't contain the item lobster pot, open bank and get the item out and then it should go fish...

 

It opens the bank but just closes it and walks away.. ?

Posted

There are quite a few logical flaws in this code :|

 

first off

if (!getBank().open()) {

You will only enter this if-statement if the attempt to open the bank fails. Did you mean !getBank().isOpen() ?

Even if that is the case, doing something only if the bank is not open is a strange way to proceed.

next:

getBank().open();
if (getBank().contains("Lobster pot"))

getBank().open() will only do the interaction. It will not wait for the actual bank widget to appear. So odds are the bank is still not open when you check for the lobster pot.

getBank().getItem("Lobster pot");

This simply gets the item instance. It does not withdraw an item from the bank. To withdraw an item, use the withdraw methods.

while (!getBank().isOpen()) {
     sleep(random(200, 300));
     localWalker.walkPath(backFishing);
}

Not sure what to even say to this part. You walk back to the finishing spot in an eternal loop until the bank is open again? How is walking back to the fishing spot ever going to result in the bank opening?
I can only see this piece of code locking the script

 

Try to revise it a bit; generally you should avoid doing multiple interactions in the same loop cycle, and also avoid potentially infinite loops.

  • Like 1
Posted
if (!getInventory().contains("Lobster pot")) {
            if (!getBank().open()) {
                getBank().open();
                if (getBank().contains("Lobster pot"))
                    getBank().getItem("Lobster pot");
                    System.out.println("Taken a lobster pot out of the bank to fish with.");
                while (!getBank().isOpen()) {
                    sleep(random(200, 300));
                    localWalker.walkPath(backFishing);
                }
                    return 2000;
                }
            }

I'm not sure why but this doesn't seem to work..

 

If my inv doesn't contain the item lobster pot, open bank and get the item out and then it should go fish...

 

It opens the bank but just closes it and walks away.. ?

 

 

You should take a look at using a state based system for your scripts.

 

That code could potentially have some bugs in it. For example, what happens if the bank opening process gets interrupted?

Your script will just walk back to the fishing spot without having retrieved a lobster pot.

 

 

 

Posted

I won't spoon feed you the answer, but your logic should be structured similarly to this:

IF inventory does not contain lobster pot
--IF bank is open
----IF bank contains lobster pot
------DO withdraw one lobster pot
----ELSE
------DO stop script
--ELSE IF in bank
----DO open bank
ELSE
DO some fishing

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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