Jump to content

Conditional Sleep Condition Randomly Ending


Robo Raptor

Recommended Posts

I'm trying to put together my first basic script, however, I'm having an issue when setting a conditional sleep. The wait condition will randomly end (earlier than the timeout condition), this will happen 5+ times until all the bars are used up.

I want the script to sleep until there are no chocolate bars left in the inventory. I've also used !myPlayer().isAnimating() with the same random stops happening.

if(inventory.contains("Knife") && inventory.contains("Chocolate bar")){
    if (bank.isOpen()){ getKeyboard().typeKey((char) 27);}
    log("Using knife with chocolate");
    inventory.getItem("Knife").interact("Use");
    inventory.getItem("Chocolate bar").interact("Use");
    log("Sleeping until no bars remain");
    Timing.waitCondition(() -> !inventory.contains("Chocolate bar"), 16000);
}

I'm using the wait condition from The Viking: 

public static boolean waitCondition(BooleanSupplier condition, int timeout)
{
    return waitCondition(condition, 20, timeout);
}

If anyone can point me in the right direction it would be helpful.

 

Link to comment
Share on other sites

4 hours ago, Robo Raptor said:

I'm trying to put together my first basic script, however, I'm having an issue when setting a conditional sleep. The wait condition will randomly end (earlier than the timeout condition), this will happen 5+ times until all the bars are used up.

I want the script to sleep until there are no chocolate bars left in the inventory. I've also used !myPlayer().isAnimating() with the same random stops happening.


if(inventory.contains("Knife") && inventory.contains("Chocolate bar")){
    if (bank.isOpen()){ getKeyboard().typeKey((char) 27);}
    log("Using knife with chocolate");
    inventory.getItem("Knife").interact("Use");
    inventory.getItem("Chocolate bar").interact("Use");
    log("Sleeping until no bars remain");
    Timing.waitCondition(() -> !inventory.contains("Chocolate bar"), 16000);
}

I'm using the wait condition from The Viking: 


public static boolean waitCondition(BooleanSupplier condition, int timeout)
{
    return waitCondition(condition, 20, timeout);
}

If anyone can point me in the right direction it would be helpful.

 

Try to use the normal ConditionalSleep method to see if its an error, with the method you are currently using.

new ConditionalSleep(16000) {
    @Override
    public boolean condition() throws InterruptedException {
        return !getInventory().contains("Chocolate bar");
    }
}.sleep();
Link to comment
Share on other sites

Thanks BravoTaco. After I tried this I got the same result but I finally figured out that this is entirely my fault.

16000 ms is not enough time to afk crush an inventory worth and I had a random return condition for onloop which skewed the 16000ms it was terminating at. I extended the maximum condition time and all is working well now.

Thanks again for the help.

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