Jump to content

Issues with 'throws InterruptedException'


Impensus

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

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