Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Bank.contains()/Bank.count() straight up not working???


    Vinny143

    Recommended Posts

    Hey,

    New to this so sorry if im posting in wrong spot.

    Been working on a script and for some reason Bank.contains(int id) doesn't work for me.

    I've tried it with multiple different items, which are 100% in my bank but it returns false for them. I also tried Bank.count(int id) for those items and got 0.

    I have no idea what I'm doing wrong. I've attached screenshots of an example with air runes, which have the id 556.

    OK well I tried to attach screenshots but they fail to upload which is an issue of itself lmao, so you're just gonna have to take my word that it doesn't work.

    Edited by Vinny143
    Link to comment
    Share on other sites

    Yeah sure, but it's nothing complitcated, I'm literally just running tests with Logger.log. I tried testing with the string name as well, but that also doesn't work.

    public class FoodCooker extends AbstractScript {
     
    static final Item cookingItem= Inventory.getItemInSlot(0);
    static final Node[] nodes = {new BankerNode(cookingItem),new CookerNode(cookingItem)};
     
    @Override
    public void onStart() {
    log("Start up tests:");
    log(Bank.contains(cookingItem.getName()));
    log(Bank.contains(cookingItem.getID()));
    log(Bank.contains("Raw lobster"));
    log(Bank.contains("Lobster"));
    log(Bank.contains("Bread"));
    log("Start up tests end -----------------");
    log("Welcome to VDog's Simple Food Cooker!");
    }
     
    ....
    }
     
    Formatting got messed up from pasting, cbs fixing it.
    I have all those items in my Bank, but I get false for every single one of them. 

     

    Edited by Vinny143
    Link to comment
    Share on other sites

    I think Bank.contains() requires you to have opened the Bank prior to calling the method. I have my own custom implementation of the method so don't really use it but maybe try opening your bank first and then checking?

    Link to comment
    Share on other sites

    5 hours ago, Vinny143 said:

    Didn't work.

    The steps I did were:

    - Login

    - Manually open bank

    - Close bank

    - Run script

    Still gave me false for every test.

    To my knowledge, the script itself will need to access the bank to know what's inside. You manually opening and closing bank before running the script = the script does not know what's in the bank and will just return false. To verify this you can move that snippet from your onStart() to the onLoop(). Once you've started the script enable user input and open & close your bank. Your test should now return true.

     

    What are you trying to achieve with this code? It may be easier to check if the Bank contains those items within your bank node instead of the onStart method.

     

    So your bank node could have something like:

            if (Bank.open()){
                if (Bank.contains(cookingItem)){
                    Bank.withdrawAll(cookingItem.getName());
                } else {
                    log("No more raw fish, ending script");
                    return -1;
                }
            }

     

    Edited by roflme
    Link to comment
    Share on other sites

    19 hours ago, roflme said:

    To my knowledge, the script itself will need to access the bank to know what's inside. You manually opening and closing bank before running the script = the script does not know what's in the bank and will just return false.

    This is how I think the implementation works. You need the script to access the bank so it loads your bank contents into memory. Manually accessing the bank won't achieve this. Try the code posted by roflme. Put it in onLoop instead of onStart

    Link to comment
    Share on other sites

    It works, but you have to use these calls to contains() when you run your code to withdraw/deposit. That's what I do at least, and it works everytime.

     

    if (Bank.open()) {
    	if (Bank.contains("Coins") {
    		Bank.withdrawAll("Coins");
    	} else {
    	// some code to withdraw and sell stuff on GE
    	}
    }

     

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.