Jump to content

Issues with 'throws InterruptedException'


Recommended Posts

Posted

Hi guys!

I am trying to use multiple classes to ease my debugging and readability.

When I make a new class and use throws 'InterruptedException' after the function declaration this allows me to use functions such as: 

sleep(random(670,944));

in my main I do the following:

private GielenorGuide doGilGuide = new GielenorGuide();
doGilGuide.exchangeContext(getBot());

However, this means when I exchange context in the onStart function and call doGilGuide.Functionname(); The script will not start.

Removing the throws InterruptedException from all function declerations will allow my script to work but at the cost of having to use conditional sleeps for literally everything which is a very verbose solution for things where you just want a simple sleep.

Is there any way I can make it so I can just use sleeps while still being able to exchange context within my main.

Posted
4 hours ago, Chris said:

yes dont use deprecated .exchangeContext()

What is the alternative? I am kind of new to OO programming coming from Python & C/C++. I have figured everything else out so far but this seems to be the last kind of hurdle for now.

58 minutes ago, Zappster said:

Maybe read an intro on try + catch statments

https://www.w3schools.com/java/java_try_catch.asp

I only wanted to implement basic 1x line sleeps instead of conditional sleeps everywhere for basic code. Try catching everything wouldn't achieve this.

Posted
2 minutes ago, Malcolm said:

Arguably you're supposed to exchange context but either or really works. I don't see an issue with doing either way.

image.thumb.png.438b8304bd9f0fbb426b0296210d75ad.png

 

If you exchange context you are supposed to extend MethodProvider in your other class and then you can call the methods within that class in your main class

For example if you exchange context you'd do something like this


 


ClassName cls = new ClassName();

public void onStart() {

cls.exchangeContext().getbot());

}

public int onLoop() {

cls.method();

return 150;

}

 

and in your other class you'd just do this


public class ClassName extends MethodProvider {

 

The alternative is to do something like this without extending MethodProvider and without exchanging context.
 


public void method(ClassName cls) {

cls.callMethod();

}

 

 

 

I do exchange context as show and extend method provider but the issue persists.

Posted

Idk why so many OSBot people create new instances of MethodProvider. Why don't you just use dependency injection, inject your already existing MethodProvider, then call directly from that..? 

 

For instance:

class Bla {

private MethodProvider methodProvider;

public Bla(MethodProvider methodProvider) {

this.methodProvider = methodProvider;

}

 

public void bla2() {

methodProvider.callSomeUselessFunction();

}

}

 

Then to create that object instance, new Bla(methodProviderInstance);

 

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