TrixxieRAyh 2 Share Posted June 7, 2021 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 More sharing options...
tawjarvis 0 Share Posted August 4, 2021 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. Link to comment Share on other sites More sharing options...
Bonfire 331 Share Posted August 4, 2021 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; } Link to comment Share on other sites More sharing options...
tawjarvis 0 Share Posted August 4, 2021 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 More sharing options...
Bonfire 331 Share Posted August 4, 2021 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. Link to comment Share on other sites More sharing options...
tawjarvis 0 Share Posted August 4, 2021 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 More sharing options...
camelCase 220 Share Posted August 5, 2021 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.