graysbotman01 Posted May 10, 2019 Posted May 10, 2019 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?
Chris Posted May 11, 2019 Posted May 11, 2019 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
Token Posted May 11, 2019 Posted May 11, 2019 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)
Spiderman Posted May 11, 2019 Posted May 11, 2019 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.
graysbotman01 Posted May 14, 2019 Author Posted May 14, 2019 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.