Z3Die Posted February 1, 2021 Share Posted February 1, 2021 (edited) Edited February 8, 2021 by Z3Die Quote Link to comment Share on other sites More sharing options...
Canidae Posted February 1, 2021 Share Posted February 1, 2021 (edited) Outside of your question, this is not how you should go on and write this code. What you are trying is to do one method call which results in buying items, without any kind of looping. That's not going to work properly and even if it will, it's unreliable. You can do multiple things. Create an Event class and execute it as an event, let your script loop through it (by using a task system for example) or write a recursive method (not sure if that's a good idea though). This is an example with an event. When you want to buy items, you will create a new event, pass through the list of items and execute the buying. If you are done buying, you set the event to finished and the script will start looping again. (Not sure if this code works and if it's 100% correct, long time ago for me). public class Main extends Script { @Override public int onLoop() throws InterruptedException { if (shouldbuyItems()) { BuyItemsEvent event = new BuyItemsEvent(buyItemList); event.exchangeContext(getBot()); execute(event); } return 300; } } public class BuyItemsEvent extends Event { private List<BuyItem> items; public BuyItemsEvent(List<BuyItem> items) { this.items = items; } @Override public int execute() throws InterruptedException { if (!getGrandExchange().isOpen()) { openGE(); } else if (boughtItems()) { setFinished(); } else { buyItems(); } return 300; } public void openGE() { RS2Object geBooth = getObjects().closest("Grand Exchange booth"); NPC exchangeWorker = getNpcs().closest("Grand Exchange Clerk"); int random = new Random().nextInt(2); if (geBooth != null && random == 0) { if (geBooth.interact("Exchange")) { new ConditionalSleep(2500, 3000) { @Override public boolean condition() { return getGrandExchange().isOpen(); } }.sleep(); } } else if (exchangeWorker != null) { if (exchangeWorker.interact("Exchange")) { new ConditionalSleep(2500, 3000) { @Override public boolean condition() { return getGrandExchange().isOpen(); } }.sleep(); } } } } I also recommend using this class for conditional sleeps: Edited February 1, 2021 by Canidae Quote Link to comment Share on other sites More sharing options...
Jarl Posted February 2, 2021 Share Posted February 2, 2021 There is no way that file doesn't exist. Anyway, it's not possible to tell how you got the null pointer exception with the code you are showing us. Most likely, some part of your code isn't null checking when dealing with widgets. But it could be something else too. Quote Link to comment Share on other sites More sharing options...
FuryShark Posted February 3, 2021 Share Posted February 3, 2021 LOOOOOOOOOOOOOOOL Quote Link to comment Share on other sites More sharing options...