Jump to content

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


graysbotman01

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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