Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

getInventory.getAmount sometimes returning 0?

Featured Replies

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

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.

  • Author
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

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

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.