Jump to content

furnace interface keeps opening repeatedly instead of staying open until I finish crafting.


CrystalChris

Recommended Posts

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...
}

 

 

Link to comment
Share on other sites

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:)

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...