Jump to content

Item isn't in inv


Kenn

Recommended Posts

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

Link to comment
Share on other sites

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

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.

 

 

 

Link to comment
Share on other sites

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