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

Potential bug: Cannot find item in inventory when starting script from CLI

Featured Replies

So I've made my first script and I ran into a problem. Whenever I run my script from CLI using the -script argument my script starts to behave differently. When my script starts, all getInventory().contains("SOMEITEM") return false for some reason. When using getInventory().getItem("SOMEITEM") it returns null. Whenever this happens, I programmed the bot to retrieve the item from the bank and when it opens the bank it suddenly remembers that it actually has the item already and continues to function normally. Note that getInventory() is not null.

The weird thing is that the script works perfectly when launched manually within the client and the problem only arises when using the -script argument. In the log I'm getting no errors. Anyone have any ideas?

12 hours ago, graysbotman01 said:

So I've made my first script and I ran into a problem. Whenever I run my script from CLI using the -script argument my script starts to behave differently. When my script starts, all getInventory().contains("SOMEITEM") return false for some reason. When using getInventory().getItem("SOMEITEM") it returns null. Whenever this happens, I programmed the bot to retrieve the item from the bank and when it opens the bank it suddenly remembers that it actually has the item already and continues to function normally. Note that getInventory() is not null.

The weird thing is that the script works perfectly when launched manually within the client and the problem only arises when using the -script argument. In the log I'm getting no errors. Anyone have any ideas?

add a 7 second sleep in the onStart at the top

 

sometimes CLI loads the script too quickly. 7 second trick has always worked for me

You could check that client is logged in before calling getInventory() or that inventory widget exists & is not = to null.

I think to check you're logged in before calling getInventory() would be >

 

if(getClient().getLoginStateValue() == 30) {
    getInventory().contains("SOMEITEM")
}

 

then if you're determined that you SHOULD be logged in, I would suggest a conditional sleep after the check and then recheck, like this >

 if(getClient().getLoginStateValue() == 30) {
    getInventory().contains("SOMEITEM")
 }
 else
 {
      new ConditionalSleep(5000) {
          @Override
          public boolean condition() {
              return getClient().getLoginStateValue() == 30;
          }
      }.sleep();
      //recall entire method or just simply " getInventory... "
 }

 

OR Scrap that entire thing and after logging in, before you begin to execute methods, simply call a conditional sleep to return true on loginstate = to 30, so >

//start of methods

     new ConditionalSleep(5000) {
          @Override
          public boolean condition() {
              return getClient().getLoginStateValue() == 30;
          }
      }.sleep();

this is mostly on the basis that your initial login hasn't failed.

  • Author
On 5/11/2019 at 1:57 PM, Chris said:

add a 7 second sleep in the onStart at the top

 

sometimes CLI loads the script too quickly. 7 second trick has always worked for me

Thanks!

On 5/12/2019 at 12:55 AM, SyntaxRS said:

You could check that client is logged in before calling getInventory() or that inventory widget exists & is not = to null.

I think to check you're logged in before calling getInventory() would be >

 


if(getClient().getLoginStateValue() == 30) {
    getInventory().contains("SOMEITEM")
}

 

then if you're determined that you SHOULD be logged in, I would suggest a conditional sleep after the check and then recheck, like this >


 if(getClient().getLoginStateValue() == 30) {
    getInventory().contains("SOMEITEM")
 }
 else
 {
      new ConditionalSleep(5000) {
          @Override
          public boolean condition() {
              return getClient().getLoginStateValue() == 30;
          }
      }.sleep();
      //recall entire method or just simply " getInventory... "
 }

 

OR Scrap that entire thing and after logging in, before you begin to execute methods, simply call a conditional sleep to return true on loginstate = to 30, so >


//start of methods

     new ConditionalSleep(5000) {
          @Override
          public boolean condition() {
              return getClient().getLoginStateValue() == 30;
          }
      }.sleep();

this is mostly on the basis that your initial login hasn't failed.

This is very useful, thank you!

On 5/11/2019 at 3:34 PM, Token said:

If this also happens when starting while logged out is because the inventory has not been loaded, and it has to be opened to fix this (same applies for equipment) 

I believe the problem was indeed due to the inventory not being loaded.

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

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.