Jump to content

RS2Object.interact() infinite loop


Recommended Posts

Posted

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!

 

Posted

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.

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

Posted

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!

Posted
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;

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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