Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Question DelayUntil bug or misunderstanding?

Joined
Feb 9, 2019
Messages
44
I have been writing my fletching bot to interact with logs and try to withdraw them from the bank. Knowing that there is currently a bug that despite the bank successfully withdrawing items, it can still return false. As such I decided to try and do a test with the Inventory to check when the required number of items was actually withdrawn. In the below code I simply used the Execution.delay inside to delay between withdrawing the logs and checking the inventory.

Code:
String key = "Maple logs";
int required = 13;
System.out.println("---Start getting item " + key + " in quantity: " + required);
boolean res = Execution.delayUntil(() -> {
    boolean ret = Bank.withdraw(key, required);
    System.out.println("How did I go with: " + key + " in quantity: " + required);
    Execution.delay(100);
    if (ret || Inventory.getQuantity(key) >= required || Inventory.isFull()) {
        System.out.println("returned out...ret " + Boolean.toString(ret) + " inv quantity: " + Inventory.getQuantity(key));
        return true;
    }
    return false;
} , 3000, 5000);
System.out.println("---Complete:  " + Boolean.toString(res));

Heres the output:
---Start getting item Maple logs in quantity: 13
How did I go with: Maple logs in quantity: 13
returned out...ret false inv quantity: 13
How did I go with: Maple logs in quantity: 13
returned out...ret false inv quantity: 26
---Complete: true

The internal function does appear to work, though despite returning "true", the Exeuction.delayUntil does not quit. What have I missed in terms of how to write this function? I know I could do the check first then do the execution so I don't need an internal delay, but generally speaking, have I miunderstood an aspect of it? Or is there a bug in it?


lb25
 
#1 Fabric Cleaner
Joined
Mar 18, 2017
Messages
393
I have been writing my fletching bot to interact with logs and try to withdraw them from the bank. Knowing that there is currently a bug that despite the bank successfully withdrawing items, it can still return false. As such I decided to try and do a test with the Inventory to check when the required number of items was actually withdrawn. In the below code I simply used the Execution.delay inside to delay between withdrawing the logs and checking the inventory.

Code:
String key = "Maple logs";
int required = 13;
System.out.println("---Start getting item " + key + " in quantity: " + required);
boolean res = Execution.delayUntil(() -> {
    boolean ret = Bank.withdraw(key, required);
    System.out.println("How did I go with: " + key + " in quantity: " + required);
    Execution.delay(100);
    if (ret || Inventory.getQuantity(key) >= required || Inventory.isFull()) {
        System.out.println("returned out...ret " + Boolean.toString(ret) + " inv quantity: " + Inventory.getQuantity(key));
        return true;
    }
    return false;
} , 3000, 5000);
System.out.println("---Complete:  " + Boolean.toString(res));

Heres the output:
---Start getting item Maple logs in quantity: 13
How did I go with: Maple logs in quantity: 13
returned out...ret false inv quantity: 13
How did I go with: Maple logs in quantity: 13
returned out...ret false inv quantity: 26
---Complete: true

The internal function does appear to work, though despite returning "true", the Exeuction.delayUntil does not quit. What have I missed in terms of how to write this function? I know I could do the check first then do the execution so I don't need an internal delay, but generally speaking, have I miunderstood an aspect of it? Or is there a bug in it?


lb25

I think you're misunderstanding the use of Execution.delayUntil, also you probably shouldn't have an Execution.delay within your Execution.delayUntil, that's just a huge janky mess of code and isn't implementing Execution.delay properly. I recommend keeping it very simple such as:
Code:
if (Bank.withdraw(item, amt){
Execution.delayUntil(() ->Inventory.isFull(), 2000,5000)
}
An execution.delay is supposed to come after a method call, so if you want to click, withdraw, or interact with something and want to make sure that it isn't spam clicking or calling this method over and over again, then you should calll execution.delay.

For more info you can take a look at Party's explanation of it in another thread:

If they're slowing your bot down then you're misusing them, and yes they should be used.

Execution.delayUntil(Callable<Boolean> condition, Callable<Boolean> resetCondition, int minDelay, int maxDelay) essentially just delays for a random period of time between minDelay and maxDelay, or until condition.call() returns true - resetCondition.call() returning true will result in the delay resetting. Let's take the example of opening the bank:
Code:
final Player local = Players.getLocal();
final LocatableEntity banker = Banks.newQuery().nearest();
if(local != null && banker != null && banker.interact("Bank")) {
Execution.delayUntil(() -> Bank.isOpen(), () -> local.isMoving, 1200, 1800);
}


1. Fetch the local player
2. Locate a banker
3. Perform the necessary null checks and interact with the banker
4. Delay:
  1. If the bank is open, exit the delayUntil statement
  2. Otherwise, if the local player is moving, reset the delay timer
  3. If the local player isn't moving, check if the random number generated between 1200 and 1800 has been exceeded, if it has then exit and return false, if it hasn't, return to step 4.1.
If any of the safety checks or the interaction in step 3 fail, the delay won't happen.
 
Last edited:
Top