CrystalChris Posted February 15 Share Posted February 15 Issue: In my script for crafting Gold Necklaces, the furnace interface keeps opening repeatedly instead of staying open until I finish crafting. Context: I’m using a loop that checks if the furnace interface is open. If not, it interacts with a nearby furnace to open it. Once opened, I store the interface in a widget holder and then proceed with crafting. However, if the widget isn’t visible (or becomes non-visible), I set a flag (interfaceOpened) to false, which then triggers another furnace interaction. This leads to the furnace interface being opened over and over again. while while (getInventory().contains(GOLD_BAR)) { RS2Object furnace = getObjects().closest("Furnace"); if (!interfaceOpened) { if (furnace != null && furnace.interact("Smelt")) { new ConditionalSleep(5000) { @Override public boolean condition() { smeltInterfaceHolder[0] = getWidgets().get(446, 23); return smeltInterfaceHolder[0] != null; } }.sleep(); interfaceOpened = true; } continue; } RS2Widget smeltInterface = smeltInterfaceHolder[0]; if (smeltInterface == null || !smeltInterface.isVisible()) { interfaceOpened = false; continue; } // Crafting code follows... } Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted Sunday at 09:13 AM Share Posted Sunday at 09:13 AM 13 hours ago, CrystalChris said: Issue: In my script for crafting Gold Necklaces, the furnace interface keeps opening repeatedly instead of staying open until I finish crafting. Context: I’m using a loop that checks if the furnace interface is open. If not, it interacts with a nearby furnace to open it. Once opened, I store the interface in a widget holder and then proceed with crafting. However, if the widget isn’t visible (or becomes non-visible), I set a flag (interfaceOpened) to false, which then triggers another furnace interaction. This leads to the furnace interface being opened over and over again. while while (getInventory().contains(GOLD_BAR)) { RS2Object furnace = getObjects().closest("Furnace"); if (!interfaceOpened) { if (furnace != null && furnace.interact("Smelt")) { new ConditionalSleep(5000) { @Override public boolean condition() { smeltInterfaceHolder[0] = getWidgets().get(446, 23); return smeltInterfaceHolder[0] != null; } }.sleep(); interfaceOpened = true; } continue; } RS2Widget smeltInterface = smeltInterfaceHolder[0]; if (smeltInterface == null || !smeltInterface.isVisible()) { interfaceOpened = false; continue; } // Crafting code follows... } replied to you on discord in the OSBot help channel Quote Link to comment Share on other sites More sharing options...
Fanny Posted Tuesday at 01:57 PM Share Posted Tuesday at 01:57 PM Looks to me like ths issue is the while loop... A simple if would be better The script onLoop function runs continuously over and over again, so whiles should be used with caution. Also, while loops should have multiple breaking options or they can get stuck. Even stopping the script won't work sometimes if you don't check if the script is stopping in the while loop. If you must use while loops, best to make a special while function with all of the necessary checks that will break out of it if needed. That way you can easily implement while loops. 1 Quote Link to comment Share on other sites More sharing options...