Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Difference between getting the count of items, and getting the count of a stack.


    Rubick

    Recommended Posts

    I'm familiar with 'getInventory().count()', which will count the amount of slots taken by whatever item. I'm trying to get a count of a stack in a single slot in the inventory. Would that be 'getInventory().getAmount()'? I'm trying to count the amount of feathers in my inventory, then wait until that number increases before continuing. 

     

     

    EDIT: Here is my method to pickup a feather so far. I want it to find the feather on the ground, select to take the feather, wait until the feather stack count increases, then set the count equal to the amount of feathers, then return the count integer.

    private void pickFeather() {
            groundFeather = getGameObjects().closest(f -> f.getName().contains("Feather"));
            if (groundFeather != null) {
                if (groundFeather.interact("Take")) {
                   sleepUntil(getInventory().count(inventoryFeather) > counter, Calculations.random(2000, 3000));
                   if (getInventory().count(inventoryFeather) > counter) {
                       counter = getInventory().count(inventoryFeather);
                    }
                }
            }
    
    Link to comment
    Share on other sites

    in this case, just stop sleeping if

     

    - groundFeather ==null

    --OR

    - !groundFeather.exists()

     

     

     

    Also, count does return the number in stack.

     

    Makes sense, I just get this error though (using groundFeather == null). 

     

    "Wrong 1st argument type. Found: boolean. Required: org.dreambot.api.utilities.impl.Condition"

     

    Which makes no sense because "groundFeather == null" is i thought?

    Link to comment
    Share on other sites

    Anyone feel free to correct me if I'm wrong (anonymous inner class);

    import org.dreambot.api.utilities.impl.Condition;
    
    .
    .
    .
    
    Condition isValid = new Condition()
    {
         public boolean verify()
         {
              return groundFeather == null;
         }
    };
    
    
    .
    .
    .
    
    
    sleepUntil(isValid, Calculations.random(500, 1000));
    Link to comment
    Share on other sites

    Makes sense, I just get this error though (using groundFeather == null). 

     

    "Wrong 1st argument type. Found: boolean. Required: org.dreambot.api.utilities.impl.Condition"

     

    Which makes no sense because "groundFeather == null" is i thought?

     

    May be a syntax error, post the new code for us to see

    Link to comment
    Share on other sites

    Feather is a ground item.

     

    Also you check when feather amount is less than 0 to also stop sleeping.

     

    Yeah I found out about groundItem today. Thanks.

     

    May be a syntax error, post the new code for us to see

     

    It wouldn't let the boolean statement "groundFeather == null" satisfy the sleepUntil, it required it's own Condition statement. Just like Pudge posted.

    public class Main extends AbstractScript {
    
        private int state;
        private int counter;
        private GroundItem groundFeather;
    
        public void onStart(){
            state = 0;
            counter = 0;
        }
    
        Condition isValid = new Condition() {
            public boolean verify() {
                return groundFeather == null;
            }
        };
    
        @Override
        public int onLoop() {
            if (state ==0) {
                pickFeather();
            }
    
            return Calculations.random(500, 1000);
        }
    
        private void pickFeather() {
            groundFeather = getGroundItems().closest(f -> f.getName().contains("Feather"));
            counter = getInventory().count("Feather");
            //System.out.println(counter);
            if (groundFeather != null) {
                if (groundFeather.interact("Take")){
                    sleepUntil(isValid, Calculations.random(500, 1000));
                }
            }
        }
    }
    
    
    Link to comment
    Share on other sites

     

    Yeah I found out about groundItem today. Thanks.

     

     

    It wouldn't let the boolean statement "groundFeather == null" satisfy the sleepUntil, it required it's own Condition statement. Just like Pudge posted.

    public class Main extends AbstractScript {
    
        private int state;
        private int counter;
        private GroundItem groundFeather;
    
        public void onStart(){
            state = 0;
            counter = 0;
        }
    
        Condition isValid = new Condition() {
            public boolean verify() {
                return groundFeather == null;
            }
        };
    
        @Override
        public int onLoop() {
            if (state ==0) {
                pickFeather();
            }
    
            return Calculations.random(500, 1000);
        }
    
        private void pickFeather() {
            groundFeather = getGroundItems().closest(f -> f.getName().contains("Feather"));
            counter = getInventory().count("Feather");
            //System.out.println(counter);
            if (groundFeather != null) {
                if (groundFeather.interact("Take")){
                    sleepUntil(isValid, Calculations.random(500, 1000));
                }
            }
        }
    }
    
    

     

     

    You need to do it like this

     

    I think you may be missing the ()->

     

    xHWaWPR.png

    Link to comment
    Share on other sites

    SleepUntil() first argument expects a type of 'Condition' : https://dreambot.org/javadocs/org/dreambot/api/methods/MethodProvider.html#sleepUntil-org.dreambot.api.utilities.impl.Condition-long-

    Where condition is actually an interface, where it expects a verify method to return a Boolean in that sense. This is why a anonymous inner class was used here. You could replace the anonymous inner class with an lambda.

     

    Feel free to correct me, I'm a bit rusty, but I'm pretty sure it's something like that.

     

     

    Edit for your edit:

     

     

    You need to do it like this

     

    I think you may be missing the ()->

     

    xHWaWPR.png

     

    Yes, that is the issue because he wasn't using the inner anonymous class, or the lambda expression as you pointed out. So it had the wrong return type.

     
    Link to comment
    Share on other sites

    You need to do it like this

     

    I think you may be missing the ()->

     

    xHWaWPR.png

     

    I see. I'm learning as much as possible lately, I really do appreciate you explaining this and helping. Is there anyway you can explain the Lambda expression part? And what it's saying in layman's terms? Essentially my question is; How is what the script is "saying" changed when adding the "() - >" before ground feather?

     

    Edit: I just saw Pudge's post above this after asking, so I think I understand now. Another explanation from another person is always helpful still.

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.