Jump to content

interact() returning true even though entity is not interacted with


abotter

Recommended Posts

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.

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

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 by abotter
Link to comment
Share on other sites

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 by Flamezzz
Link to comment
Share on other sites

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 by abotter
Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...