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
  • Try asking for help in the chatbox
  • Can't figure out the GE.. *frustration*


    TrixxieRAyh
     Share

    Recommended Posts

    Hey yall!

     

    I've been working on script, and I want to allow the user to be as lazy as possible, so if there is not enough needed items in bank/inventory, the bot would open up the GE and buy needed items. Now apologises for my rough looking code but this is what I have for my GE:

    public void buyMore(String item) {
            if(!(Inventory.count("Coins") >= 100)) {
                if (Bank.openClosest()) {
                    if(Bank.count("Coins") >= 100) {
                        Bank.withdraw("Coins", 100);
                        Bank.close();
                        sleep(5000);
                        GrandExchange.open();
                        if (GrandExchange.isOpen()) {
                            log("GE IS OPEN");
                            GrandExchange.openBuyScreen(GrandExchange.getFirstOpenSlot());
                            log("BUY OPENED");
                            sleep(1000);
                            if (GrandExchange.buyItem(item, 100, 100)) {
                                log("BOUGHT ITEM");
                                if (sleepUntil(GrandExchange::isReadyToCollect, 15000)) {
                                    GrandExchange.collect();
                                    GrandExchange.close();
                                    if (Bank.openClosest()) {
                                        Bank.depositAllItems();
                                    }
                                }
                            }
                        }
                    } else {
                        log("Not enough coins to function, stopping..");
                        stop();
                    }
                }
            } else {
                GrandExchange.open();
                if (GrandExchange.isOpen()) {
                  	GrandExchange.openBuyScreen(GrandExchange.getFirstOpenSlot());
                    sleep(1000);
                    if (GrandExchange.buyItem(item, 100, 100)) {
                        if (sleepUntil(GrandExchange::isReadyToCollect, 15000)) {
                            GrandExchange.collect();
                            GrandExchange.close();
                            if (Bank.openClosest()) {
                                Bank.depositAllItems();
                            }
                        }
                    }
                }
            }
        }

    The problem I have with this is that the bot opens GE "main widget" but never opens the buy window and buys any items.. What am I missing?

    Link to comment
    Share on other sites

    • 1 month later...

    Could you try adding a short sleep or a sleepUntil GE is actually open?

    In your code here:

    GrandExchange.open();
    if (GrandExchange.isOpen()) {

    I Believe you have a high chance that GE isn't open yet.

    Whenever I open anything, I add something like:

    GrandExchange.open();
    while(!GrandExchange.isOpen()) sleep(300,900);

    It's probably also better to also wrap the .open in an if() statement for if it should fail.

    Edit: Oh wow, sorry for the bump, didn't see.

    Edited by tawjarvis
    Didn't notice this post was from june.
    Link to comment
    Share on other sites

    3 minutes ago, tawjarvis said:

    Could you try adding a short sleep or a sleepUntil GE is actually open?

    In your code here:

    GrandExchange.open();
    if (GrandExchange.isOpen()) {

    I Believe you have a high chance that GE isn't open yet.

    Whenever I open anything, I add something like:

    GrandExchange.open();
    while(!GrandExchange.isOpen()) sleep(300,900);

    It's probably also better to also wrap the .open in an if() statement for if it should fail.

    You're better off utilizing the returns from the GrandExchange methods. Also, I would heavily discourage using While loops within your scripts unless absolutely necessary. One possible solution could be as follows:

    if (!GrandExchange.isOpen() && GrandExchange.open()) {
      MethodProvider.sleepUntil(GrandExchange::isOpen, someSleepTime, somePollingRate);
      ...
      return someValue;
    }

     

    Edited by Bonfire
    Link to comment
    Share on other sites

    12 hours ago, Bonfire said:

    You're better off utilizing the returns from the GrandExchange methods.

    Yeah, that's probably the best option. I think the main problem boiled down to the GE not being open at the time of the other actions being engaged.

    What are some benefits / differences between sleepUntil and a regular While loop?
    Will both not block the thread indefinitely until the GE is open?

    Link to comment
    Share on other sites

    30 minutes ago, tawjarvis said:

    Yeah, that's probably the best option. I think the main problem boiled down to the GE not being open at the time of the other actions being engaged.

    What are some benefits / differences between sleepUntil and a regular While loop?
    Will both not block the thread indefinitely until the GE is open?

    You are correct in saying that both are blocking, but sleepUntil will not block the thread indefinitely (if you don't let it). After the sleepUntil's timeout has elapsed, it will stop sleeping and continue. With your while loop, your script thread will be blocked indefinitely.

    Say, for example, you click "Open Grand Exchange" just fine but something stops you before you actually get to open it (maybe someone uses a Bond on you or something). With the sleepUntil it will timeout after X amount of time and you will just retry the "Open" interact. With the while loop, you would sit there indefinitely.

    Overall, I personally think that it is much easier to shoot yourself in the foot and make a script hang when using while loops. Utilizing the built in sleep and sleepUntil methods is safer in my opinion. Leaves less room for error.

    Edited by Bonfire
    Link to comment
    Share on other sites

    You're probably right, I just couldn't get them to work originally so I fell back to what I knew.

    Looks like I have some rewriting to do then, thanks for the clarfication 🙂

    Link to comment
    Share on other sites

    On 6/7/2021 at 7:13 AM, TrixxieRAyh said:

    Hey yall!

     

    I've been working on script, and I want to allow the user to be as lazy as possible, so if there is not enough needed items in bank/inventory, the bot would open up the GE and buy needed items. Now apologises for my rough looking code but this is what I have for my GE:

    public void buyMore(String item) {
            if(!(Inventory.count("Coins") >= 100)) {
                if (Bank.openClosest()) {
                    if(Bank.count("Coins") >= 100) {
                        Bank.withdraw("Coins", 100);
                        Bank.close();
                        sleep(5000);
                        GrandExchange.open();
                        if (GrandExchange.isOpen()) {
                            log("GE IS OPEN");
                            GrandExchange.openBuyScreen(GrandExchange.getFirstOpenSlot());
                            log("BUY OPENED");
                            sleep(1000);
                            if (GrandExchange.buyItem(item, 100, 100)) {
                                log("BOUGHT ITEM");
                                if (sleepUntil(GrandExchange::isReadyToCollect, 15000)) {
                                    GrandExchange.collect();
                                    GrandExchange.close();
                                    if (Bank.openClosest()) {
                                        Bank.depositAllItems();
                                    }
                                }
                            }
                        }
                    } else {
                        log("Not enough coins to function, stopping..");
                        stop();
                    }
                }
            } else {
                GrandExchange.open();
                if (GrandExchange.isOpen()) {
                  	GrandExchange.openBuyScreen(GrandExchange.getFirstOpenSlot());
                    sleep(1000);
                    if (GrandExchange.buyItem(item, 100, 100)) {
                        if (sleepUntil(GrandExchange::isReadyToCollect, 15000)) {
                            GrandExchange.collect();
                            GrandExchange.close();
                            if (Bank.openClosest()) {
                                Bank.depositAllItems();
                            }
                        }
                    }
                }
            }
        }

    The problem I have with this is that the bot opens GE "main widget" but never opens the buy window and buys any items.. What am I missing?

    id guess the problem is after GrandExchange.open() it checks near instantly if its open, which ofc its not because it doesnt click and load that fast, you can replace if (GrandExchanage.isopen()) with if (GrandExchange.open()) // this will open the ge if its not already open

    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
     Share

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