Sujamma Posted May 14, 2020 Share Posted May 14, 2020 (edited) I am trying to make a script that completes Cook's Assistant. I go to the Lumby Mill to make flour. After taking the grain from the field I want the bot to go to the mill, but the Conditional Sleep sleeps until timeout without detecting that the condition is true. The Conditional Sleep waits until the gate is open. Here's the code: private boolean GoToMill2(){ Position preMillPos = new Position(3166, 3300, 0); RS2Object gate = objects.closest("Gate"); if (!IsOpen(gate)){ gate.interact("Open"); new ConditionalSleep(5000, 600){ @Override public boolean condition() throws InterruptedException { return IsOpen(gate); } }.sleep(); } WalkingEvent walk = new WalkingEvent(preMillPos); walk.setMinDistanceThreshold(2); execute(walk); return true; } private boolean IsOpen(RS2Object object){ return Arrays.asList(object.getDefinition().getActions()).contains("Close"); } All help is appreciated! Edited May 14, 2020 by Sujamma Quote Link to comment Share on other sites More sharing options...
Lol_marcus Posted May 14, 2020 Share Posted May 14, 2020 (edited) Misread what your error was. Let me take another look. Edited May 14, 2020 by Lol_marcus Quote Link to comment Share on other sites More sharing options...
Sujamma Posted May 14, 2020 Author Share Posted May 14, 2020 (edited) 13 minutes ago, Lol_marcus said: The only error I got when running it is that it's missing a "}" after .sleep();. What error are you getting exactly? private boolean GoToMill2(){ Position preMillPos = new Position(3166, 3300, 0); RS2Object gate = objects.closest("Gate"); if (!IsOpen(gate)){ gate.interact("Open"); new ConditionalSleep(5000, 600){ @Override public boolean condition() throws InterruptedException { return IsOpen(gate); } }.sleep(); } That's weird. I am not getting any errors in IntelliJ when building and I can run the script in the OSBot client. But I have detected my problem. My problem was that ConditionalSleep didn't stop sleeping even though the gate was open. The real culpirt was IsOpen() method . It returns false even though the gate is open. So my question now would be - how do I reliably detect if the gate is open or not? Edited May 14, 2020 by Sujamma Detected was spelled wrong Quote Link to comment Share on other sites More sharing options...
Geeseball Posted May 14, 2020 Share Posted May 14, 2020 (edited) Edit: the IsOpen function is not for a gate but for the bank I believe. Try this: gate.getDefinition().getActions()).contains("Close") Then you will know if it is open or not. Edited May 14, 2020 by Geeseball Quote Link to comment Share on other sites More sharing options...
Lol_marcus Posted May 14, 2020 Share Posted May 14, 2020 As far as I know WebWalking does all the interaction with objects. Maybe get the coords of where you want your character to go and let WebWalking do the rest? Quote Link to comment Share on other sites More sharing options...
Gunman Posted May 14, 2020 Share Posted May 14, 2020 @Sujamma Try this and see what happens. Wonder if something is getting messed up with the Arrays.asList or something. new ConditionalSleep(5000, 600){ @Override public boolean condition() throws InterruptedException { return gate.hasAction("Close"); } }.sleep(); Quote Link to comment Share on other sites More sharing options...
Sujamma Posted May 14, 2020 Author Share Posted May 14, 2020 3 minutes ago, Geeseball said: Why did you make GoToMill2 a boolean and not a void? Does this work? private void GoToMill2() throws InterruptedException { Position preMillPos = new Position(3166, 3300, 0); RS2Object gate = objects.closest("Gate"); if (!IsOpen(gate)){ gate.interact("Open"); new ConditionalSleep(5000, 600){ @Override public boolean condition() { return IsOpen(gate); } }.sleep(); } WalkingEvent walk = new WalkingEvent(preMillPos); walk.setMinDistanceThreshold(2); execute(walk); } private boolean IsOpen(RS2Object object){ return Arrays.asList(object.getDefinition().getActions()).contains("Close"); } Nope, changing the return type does not work. Right now the code consists entirely of the method GoToMill2() and IsOpen(), so it doesn't really matter what GoToMill2() returns. The problem is with IsOpen() as I recently discovered. I don't know how to reliably detect if a gate is open or not. Quote Link to comment Share on other sites More sharing options...
Camaro Posted May 14, 2020 Share Posted May 14, 2020 gate.getDefinition().getActions() returns a list of all possible actions that the gate could have. It is not directly related to the instance and what it actually has. use gate.hasAction("Close") Quote Link to comment Share on other sites More sharing options...
Sujamma Posted May 14, 2020 Author Share Posted May 14, 2020 3 minutes ago, Gunman said: @Sujamma Try this and see what happens. Wonder if something is getting messed up with the Arrays.asList or something. new ConditionalSleep(5000, 600){ @Override public boolean condition() throws InterruptedException { return gate.hasAction("Close"); } }.sleep(); Changed IsOpen(gate) with gate.hasAction("Close") and it still returns false even though the gate is open. Quote Link to comment Share on other sites More sharing options...
Kramnik Posted May 14, 2020 Share Posted May 14, 2020 13 minutes ago, Geeseball said: Edit: the IsOpen function is not for a gate but for the bank I believe. Try this: gate.getDefinition().getActions()).contains("Close") Then you will know if it is open or not. 2 minutes ago, Camaro said: gate.getDefinition().getActions() returns a list of all possible actions that the gate could have. It is not directly related to the instance and what it actually has. use gate.hasAction("Close") But in some cases this wouldn't work. E.g. if you doing tut island I don't think that it would have close option since the gate closes immediately itself Quote Link to comment Share on other sites More sharing options...
Geeseball Posted May 14, 2020 Share Posted May 14, 2020 2 minutes ago, Kramnik said: But in some cases this wouldn't work. E.g. if you doing tut island I don't think that it would have close option since the gate closes immediately itself Ah that is good to know thanks! For know I think my or @Camaro solution should fix @Sujamma problem. Quote Link to comment Share on other sites More sharing options...
Sujamma Posted May 14, 2020 Author Share Posted May 14, 2020 16 minutes ago, Lol_marcus said: As far as I know WebWalking does all the interaction with objects. Maybe get the coords of where you want your character to go and let WebWalking do the rest? I am using WalkingEvent, because I think that webWalk is using more processing power(or is it?) and should be used for long distances . But if nothing else works I'll use webWalk. Quote Link to comment Share on other sites More sharing options...
Gunman Posted May 14, 2020 Share Posted May 14, 2020 @Sujamma @Camaro I just tested it and it's uses the old data of gate. It's not refreshing and checking for new action data. I don't know why, because it worked just fine on a plough which is a NPC but idk if this difference is gonna do anything Quote Link to comment Share on other sites More sharing options...
Geeseball Posted May 14, 2020 Share Posted May 14, 2020 7 minutes ago, Sujamma said: I am using WalkingEvent, because I think that webWalk is using more processing power(or is it?) and should be used for long distances . But if nothing else works I'll use webWalk. Yes it uses more processing power. But you can ask yourself wheter it is more convenient to write a separate piece of script for each gate instead of using webwalk. I think it depends on the distance you have to travel including the obstacles. Quote Link to comment Share on other sites More sharing options...
progamerz Posted May 14, 2020 Share Posted May 14, 2020 (edited) @Sujamma It doesn't work because theoretically, it never changes the value of gate again, so it is stored as an old object which is closed, what you can do is use this new ConditionalSleep(5000, 600) { @Override public boolean condition() { return getObjects().closest(o -> o.getName().equals("Gate") && o.getPosition().equals(gate.getPosition()) && !o.hasAction("Open")) != null; } }.sleep(); The way this works, is that it keeps checking every 600ms if the condition is true, here we are trying to find new object which has the same position as the gate which we interacted but is opened Edited May 14, 2020 by progamerz Quote Link to comment Share on other sites More sharing options...