Jump to content

ConditionalSleep Always Timing Out


gumibearscuz

Recommended Posts

I have a fairly simple script that I was testing and I realized all of my ConditionalSleeps are just timing out. E.g.

RS2Widget widget = api.getWidgets.get(270, 14);
if (widget != null) {
  if (widget.interact("Make")) {
    boolean result = new ConditionalSleep(10000, 16000) {
      @Override
      public boolean condition() throws InterruptedException {
        api.log("Vial amount: " + api.getInventory().getAmount("Vial of water");
        api.log("Herb amount: " + api.getInventory().getAmount("Ranarr weed");
        return api.getInventory().getAmount("Vial of water") == 0 || api.getInventory().getAmount("Ranarr weed") == 0;
      }
    }.sleep();
    api.log("ConditionalSleep returned: " + result);
  }
}

Results in logging "Vial amount: 14" "Herb amount: 14" "ConditionalSleep returned: false" every time. It doesn't even check the condition more than once.

Link to comment
Share on other sites

10 hours ago, gumibearscuz said:

I have a fairly simple script that I was testing and I realized all of my ConditionalSleeps are just timing out. E.g.


RS2Widget widget = api.getWidgets.get(270, 14);
if (widget != null) {
  if (widget.interact("Make")) {
    boolean result = new ConditionalSleep(10000, 16000) {
      @Override
      public boolean condition() throws InterruptedException {
        api.log("Vial amount: " + api.getInventory().getAmount("Vial of water");
        api.log("Herb amount: " + api.getInventory().getAmount("Ranarr weed");
        return api.getInventory().getAmount("Vial of water") == 0 || api.getInventory().getAmount("Ranarr weed") == 0;
      }
    }.sleep();
    api.log("ConditionalSleep returned: " + result);
  }
}

Results in logging "Vial amount: 14" "Herb amount: 14" "ConditionalSleep returned: false" every time. It doesn't even check the condition more than once.


Look into using this:


& write your code something like this:

if (widget != null) {
  if (widget.interact("Make")) {
	api.log("Vial amount: " + api.getInventory().getAmount("Vial of water");
   	api.log("Herb amount: " + api.getInventory().getAmount("Ranarr weed");
	Sleep.sleepUntil(()-> api.getInventory().getAmount("Vial of water") == 0 || api.getInventory().getAmount("Ranarr weed") == 0, 20000);
   	api.log("ConditionalSleep returned: " + result);
	}
}


 

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