Jump to content

ConditionalSleep Always Timing Out


Recommended Posts

Posted

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.

Posted
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);
	}
}


 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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