abotter Posted May 21, 2015 Share Posted May 21, 2015 Hi there. I'm making a simple Mining Guild bot. I'm having an issue where the bot will sometimes misclick the ladders or coal veins and get stuck. I am currently using the following snippet to perform the interaction (example below is for climbing down the ladder): RS2Object ladder = objects.closest("Ladder"); while (!ladder.interact("Climb-down")) sleep(100); I believe interact() may be returning true even though the ladder/vein was not properly interacted with. I was wondering if anyone else was having this issue. Thanks in advance for the help. Quote Link to comment Share on other sites More sharing options...
Mysteryy Posted May 22, 2015 Share Posted May 22, 2015 Hi there. I'm making a simple Mining Guild bot. I'm having an issue where the bot will sometimes misclick the ladders or coal veins and get stuck. I am currently using the following snippet to perform the interaction (example below is for climbing down the ladder): RS2Object ladder = objects.closest("Ladder"); while (!ladder.interact("Climb-down")) sleep(100); I believe interact() may be returning true even though the ladder/vein was not properly interacted with. I was wondering if anyone else was having this issue. Thanks in advance for the help. I have been in scripting for a long time now, I am just going to tell you that 1) Using a while loop in this manner is a bad idea. 2) Do not ever depend on one of the methods to return a correct boolean. 3) You dont have a single null check on the ladder What if the interaction was successful, but the interaction still returned false? Then that while loop would likely get stuck trying to interact with an object that doesnt exist, and your script would do nothing. Dont use the return values in this manner, and dont use a while loop in this manner. This type of logic is shakey and be easily broken. Make your script stable by having a strong baseline of logic that can handle any situation. 1 Quote Link to comment Share on other sites More sharing options...
Botre Posted May 22, 2015 Share Posted May 22, 2015 I believe interact() may be returning true even though the ladder/vein was not properly interacted with. The boolean just reflects whether a mouse click was transmitted to the entity's (option's) click region. You might want to check whether you are in the area below or above the ladder (actual proof of whether the interaction was succesfull) instead of relying on that metho's boolean too much. Quote Link to comment Share on other sites More sharing options...
abotter Posted May 22, 2015 Author Share Posted May 22, 2015 (edited) Thanks for the input. I'm new to RS Scripting. Seems confusing for interact to return true when interaction has not actually occurred. What would you guys recommend then? Something like: RS2Object ladder = getScript().objects.closest("Ladder"); if (ladder != null) { while (UPPER_LADDER_AREA.contains(myPlayer())) { ladder.interact("Climb-down"); sleep(100); } } Thanks again for the input. Edited May 22, 2015 by abotter Quote Link to comment Share on other sites More sharing options...
Flamezzz Posted May 22, 2015 Share Posted May 22, 2015 (edited) I'd use something like:if floor = 1 then attempt to click ladder wait for a small amount of time if moving/animating then wait a little longer (LocalWalker#waitUntilIdle() or smth similar)As Mysteryy points out you shouldn't use a while loop. You want to do 1 action each time the onLoop method executes. Edited May 22, 2015 by Flamezzz Quote Link to comment Share on other sites More sharing options...
abotter Posted May 22, 2015 Author Share Posted May 22, 2015 (edited) As Mysteryy points out you shouldn't use a while loop. You want to do 1 action each time the onLoop method executes. I see the issue now. I am performing more than one action in the walk states. Currently I am using the State paradigm with four states: BANK, MINE, WALK_TO_BANK, and WALK_TO_MINE. I guess Ill have to expand the WALK_TO_MINE state to WALK_TO_UPPER_LADDERS, GO_DOWN_UPPER_LADDERS, and WALK_TO_MINE, and a similar expansion for the WALK_TO_BANK state. Thanks you all for the help. I'll try implementing this and see if it works. Edited May 22, 2015 by abotter Quote Link to comment Share on other sites More sharing options...
FrostBug Posted May 22, 2015 Share Posted May 22, 2015 I see the issue now. I am performing more than one action in the walk states. Currently I am using the State paradigm with four states: BANK, MINE, WALK_TO_BANK, and WALK_TO_MINE. I guess Ill have to expand the WALK_TO_MINE state to WALK_TO_UPPER_LADDERS, GO_DOWN_UPPER_LADDERS, and WALK_TO_MINE, and a similar expansion for the WALK_TO_BANK state. Thanks you all for the help. I'll try implementing this and see if it works. Generally speaking you should not ever use potentially infinite loops. You should do your action, and determine the result from the state / positions of the player or its surroundings. If your state does not change as a result of the action; try the action again in the next loop. Quote Link to comment Share on other sites More sharing options...