1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Question DelayUntil bug or misunderstanding?

Discussion in 'Developer Support' started by lb25, Apr 1, 2019.

  1. lb25

    Joined:
    Feb 9, 2019
    Messages:
    44
    Likes Received:
    3
    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 (Text):
    1. String key = "Maple logs";
    2. int required = 13;
    3. System.out.println("---Start getting item " + key + " in quantity: " + required);
    4. boolean res = Execution.delayUntil(() -> {
    5.     boolean ret = Bank.withdraw(key, required);
    6.     System.out.println("How did I go with: " + key + " in quantity: " + required);
    7.     Execution.delay(100);
    8.     if (ret || Inventory.getQuantity(key) >= required || Inventory.isFull()) {
    9.         System.out.println("returned out...ret " + Boolean.toString(ret) + " inv quantity: " + Inventory.getQuantity(key));
    10.         return true;
    11.     }
    12.     return false;
    13. } , 3000, 5000);
    14. 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
     
  2. Fabreze

    Fabreze #1 Fabric Cleaner

    Joined:
    Mar 18, 2017
    Messages:
    388
    Likes Received:
    106
    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 (Text):
    1. if (Bank.withdraw(item, amt){
    2. Execution.delayUntil(() ->Inventory.isFull(), 2000,5000)
    3. }
    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:

     
    #2 Fabreze, Apr 1, 2019
    Last edited: Apr 1, 2019

Share This Page

Loading...