Xtra 31 Author Posted June 12, 2020 10 minutes ago, Pandemic said: What I mean is, you should call: makeAll = getWidgets().getWidgetChild(270, 14); right before you check if it's null, after the sleep Thank you! This worked well. Tofu was kind enough to PM me a suggestion that also worked great. So thanks both of you! Edit: Also, I see what you mean about calling it right before - apologies for misunderstanding
TheCloakdOne 389 Posted June 12, 2020 log("CB_3"); furnace.interact(); // Static sleeps are a bit meh (you can add anti-pattern sleep on top of this): sleepUntil(() -> getWidgets().getWidgetChild(270,14) != null && getWidgets().getWidgetChild(270,14).isVisible(), 3000) // Interact with the widgetChild makeAll.interact(); // This makes the bot wait until a level-up dialogue appears // and waits for it to finish smelting sleepUntil(() -> getDialogues().continueDialogue() || !getInventory().contains("Steel bar"), 180000); Try a sleepUntil instead of the sleep, should sort out your issue
Xtra 31 Author Posted June 12, 2020 I tried sleepUntil(() -> makeAll != null, 8000); And it just waits the full 8 seconds, which doesn't make sense as it's not null, and I have the right widget ID for it. It is better after the previous suggestions - but I still occasionally get NullPointerExceptions with the current code i'm using: log("CB_1"); if (furnaceArea.contains(getLocalPlayer())) { furnace.interact(); sleep(Calculations.random(1250, 1800)); makeAll = getWidgets().getWidgetChild(270, 14); sleepUntil(() -> makeAll.isVisible(), 8000); log("CB_2"); if (makeAll != null) { log("CB_3"); makeAll.interact(); sleepUntil(() -> getDialogues().continueDialogue() || !getInventory().contains("Steel bar"), 180000); } } else if (getWalking().shouldWalk(Calculations.random(2, 5))) { log("CB_5"); getWalking().walk(furnaceArea.getRandomTile()); } return 300; I understand why I am getting NPE's, but if I add a null check, it just assumes it is false and wait's for the full sleepUntil duration, no matter what I try. I have tried putting the sleeps/sleepUntils before and after I get the widgets, and I've tried using isVisible which works nice, but the NPE's..
Pandemic 2853 Posted June 13, 2020 You're trying to check if it's visible before checking if it's null. You'd need to replace this: makeAll = getWidgets().getWidgetChild(270, 14); sleepUntil(() -> makeAll.isVisible(), 8000); to something like this: sleepUntil(() -> getWidgets().getWidgetChild(270, 14) != null && getWidgets().getWidgetChild(270, 14).isVisible(), 8000); makeAll = getWidgets().getWidgetChild(270, 14);
Xtra 31 Author Posted June 13, 2020 2 minutes ago, Pandemic said: You're trying to check if it's visible before checking if it's null. You'd need to replace this: makeAll = getWidgets().getWidgetChild(270, 14); sleepUntil(() -> makeAll.isVisible(), 8000); to something like this: sleepUntil(() -> getWidgets().getWidgetChild(270, 14) != null && getWidgets().getWidgetChild(270, 14).isVisible(), 8000); makeAll = getWidgets().getWidgetChild(270, 14); Oh! I see why that works now! Before I tried something similar to what you have suggested, but instead of the getWidgets() etc I used makeAll before it was initialised, because I assumed that the Private WidgetChild makeAll; would mean it would still work. But knowing that now really helps me. Thanks Pandemic you're awesome
Xtra 31 Author Posted June 13, 2020 Here's the working code in case anyone looking at this has had similar issues or just wants a simple cannonball smithing script (you will have to add banking as another node). import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.map.Area; import org.dreambot.api.script.TaskNode; import org.dreambot.api.wrappers.interactive.GameObject; import org.dreambot.api.wrappers.widgets.WidgetChild; import java.util.spi.CalendarDataProvider; public class SmithNode extends TaskNode { private Area furnaceArea = new Area(3106, 3500, 3109, 3497); private GameObject furnace; private WidgetChild makeAll; @Override public boolean accept() { return getInventory().contains("Steel bar") && getInventory().contains("Ammo mould"); } @Override public int execute() { furnace = getGameObjects().closest("Furnace"); if (furnaceArea.contains(getLocalPlayer())) { furnace.interact(); sleepUntil(() -> getWidgets().getWidgetChild(270, 14) != null && getWidgets().getWidgetChild(270, 14).isVisible(), 8000); makeAll = getWidgets().getWidgetChild(270, 14); if (makeAll != null) { makeAll.interact(); sleepUntil(() -> getDialogues().continueDialogue() || !getInventory().contains("Steel bar"), 180000); } } else if (getWalking().shouldWalk(Calculations.random(2, 5))) { getWalking().walk(furnaceArea.getRandomTile()); } return 300; } }
Recommended Posts
Archived
This topic is now archived and is closed to further replies.