Jump to content

getInventory.getAmount sometimes returning 0?


sombotdude

Recommended Posts

So I noticed that some of my bots had been sporadically stopping when left over night, but when I logged back in none of them had met the conditions I set in the script for it to stop and log out.

Basically the script logs out and stops if it has less than 2GP left in its inventory, checked by using the following code & with it logging how much GP it has left in the inventory before doing so:

log("Coins in inventory: " + getInventory().getAmount("Coins"));
if (getInventory().getAmount("Coins") > 2) {
	//do stuff
} else {
  	log("No coins left in inventory! Logging out.");
	stop(); 
}

So by checking the log I would see something like this:

"Coins in inventory: 17698"

"Coins in inventory: 17696"

"Coins in inventory: 17694"

"Coins in inventory: 0"

"No coins left in inventory! Logging out."

Yet then when I log back into the account, it has 17694 GP still in its inventory? Anybody know of why the getInventory().getAmount("Coins") would return 0, despite there still being thousands of GP in the inventory?

Also  note that the GP doesn't go anywhere in the script, the script purely just buys an item through dialogue with an NPC, with the GP just sat in the inventory.

Edit - Here's an actual screenshot from the log as it happened again as I was watching: 

getInventory.PNG.e5b9675560e5daee86cb706dd61841ee.PNG

Note I also added getAmount(995) (hence the (ID) Coins in inventory: ) just test if it was some issue with it checking the getAmount("Coins).

Thanks in advance for any help. 

Edited by sombotdude
Better Example
Link to comment
Share on other sites

14 minutes ago, NoxMerc said:

Can you replicate the issue?  Run a test script that looks like


    @Override
    public int onLoop() throws InterruptedException {
        log(getInventory().getAmount("Coins"));
        return 500;
    }

While this is running, go through the same process manually that your bot does, and see if you notice it occasionally logging 0.

Yeah this it what I have just been trying, as of yet I cannot get it to log 0 and I'm not too hopefully of being able to see it do so, as sometimes the script runs for 17 hours+ with no issues.

Edited by sombotdude
Link to comment
Share on other sites

You could do something like

int verificationAttempts = 5;
long goldAmt = 0;
for (int i = 0; i < verificationAttempts; i++) {
  goldAmt = getInventory().getAmount("Coins");
  if (goldAmt > 0)
    break;
}
if (goldAmt == 0) {
  // We tried 5 times to find gold 
}

Granted this isn't perfect, but if your assumption is true that it's somehow returning 0 at times...

I'm still convinced there's a flaw in the script's logic somewhere, and this is pretty hackish.

Edited by NoxMerc
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...