Rubick 30 Posted July 5, 2017 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); } } }
Polymorphism 48 Posted July 5, 2017 in this case, just stop sleeping if - groundFeather ==null --OR - !groundFeather.exists() Also, count does return the number in stack.
Rubick 30 Author Posted July 5, 2017 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?
Pudge 0 Posted July 5, 2017 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));
Manly 879 Posted July 5, 2017 Feather is a ground item. Also you check when feather amount is less than 0 to also stop sleeping.
Polymorphism 48 Posted July 5, 2017 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
Rubick 30 Author Posted July 5, 2017 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)); } } } }
Polymorphism 48 Posted July 5, 2017 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 ()->
Pudge 0 Posted July 5, 2017 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 ()-> 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.
Rubick 30 Author Posted July 6, 2017 You need to do it like this I think you may be missing the ()-> 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.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.