Jump to content

RS2Object.interact() infinite loop


ChrisJ

Recommended Posts

Hello everyone.

This is a bug report / call for help to make my script work. In the abyss, i run RS2Object.interact() on one of the obstacles in the outer ring to go through. Sometimes this method is called on an unlucky moment and the player is already in the inner ring. When this happens the bot keeps clicking on the minimap every ~5 seconds to go towards the object, which obviously wont work because it cannot reach it. The log after the interact() method is never called untill i stop the script.

I had a look at the source for the interact() method, and took that + added setMaximumAttempts() on the interactionEvent.

final InteractionEvent interactionEvent = new InteractionEvent(closest, outerRingObject.getObjectOption());
interactionEvent.setMaximumAttempts(3);
this.getBot().getEventExecutor().execute(interactionEvent);
failed = !interactionEvent.hasFinished();

It still entered an endless loop on the execute()...

 

I tried starting a seperate thread to set the interactionEvent as finished when the player ended up in the inner ring.. Also didnt help:

new Thread(() -> {
    long start = System.currentTimeMillis();
    while (!interactionEvent.hasFinished() && (System.currentTimeMillis() - start < 25000)) {
        if (getState() == State.INNER_RING) {
            interactionEvent.interrupt();
            interactionEvent.setFinished();
        } else {
            w8(2500 + random(500));
        }
    }
}).start();

Made the script override onMessage() to set a waitingForObstacle boolean when the message pops up that we try to mine/distract/go through, and set it to false again when the succes or fail message pops up. To make sure we dont call interact() while mining/distracting or w/e.

Checked that boolean just before starting the interactionEvent

if (waitingForObstacle) {
    return 450 + random(450);
}

And added another check that we're in the outer ring and not the inner ring

if (getState().equals(State.OUTER_RING)) { ...

 

Still it ended up trying to interact with the object in the outer ring while being in the inner ring...

Any help is appreciated!

 

Link to comment
Share on other sites

I'm not exactly sure what the structure of your script looks like but can you try switching
 

final InteractionEvent interactionEvent = new InteractionEvent(closest, outerRingObject.getObjectOption());
interactionEvent.setMaximumAttempts(3);
this.getBot().getEventExecutor().execute(interactionEvent);

to:
 

final InteractionEvent interactionEvent = new InteractionEvent(closest, outerRingObject.getObjectOption());
interactionEvent.setMaximumAttempts(3);
log("Event has finished = " + (this.getBot().getEventExecutor().execute(interactionEvent).hasFinished()));

Then check the logger whether you're getting that message or not.

Link to comment
Share on other sites

33 minutes ago, ChrisJ said:

@IDontEB Yea that's equivalent to what i did to test. It usually runs fine but sometimes gets stuck in the .execute(interactionEvent) part and won't log the message.

Either somewhere else your script just reloops that one part or the final on the declaration is interfering with the how Osb executes events. 

Link to comment
Share on other sites

This might be really dumb, but you can't you put your code in an if(canReach && pos == outerring)?

Wouldn't this stop clicking the object?

To be sure, you could put a break condition in your event, to stop it if the player is in the outerring/object is no longer reachable.

 

So basically:

If (canReach && pos == outerring) { //only execute event if we can reach the object and we're in the outerring

   Interaction event // set the interaction event to manually stop the event if we're in the innerring/object is not reachable

}

 

I just started scripting myself, don't know if this will help you!

 

Goodluck!

Link to comment
Share on other sites

20 minutes ago, CJ7 said:

This might be really dumb, but you can't you put your code in an if(canReach && pos == outerring)?

Wouldn't this stop clicking the object?

To be sure, you could put a break condition in your event, to stop it if the player is in the outerring/object is no longer reachable.

 

 So basically:

 If (canReach && pos == outerring) { //only execute event if we can reach the object and we're in the outerring

   Interaction event // set the interaction event to manually stop the event if we're in the innerring/object is not reachable

}

 

I just started scripting myself, don't know if this will help you!

 

Goodluck!

Considering you're using a state method, couldn't you just break the state if the outer loop method is run if you're in the inner loop?

I'm not quite sure how or why your state is executing as you're not showing us the code, but I'd assume that would solve it.

case OUTER_LOOP:
	if (INNER_LOOP_AREA.contains(Player)) {
		break;
	}

	// rest of code
	break;

 

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...