Impensus Posted April 19, 2019 Share Posted April 19, 2019 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. Quote Link to comment Share on other sites More sharing options...
Chris Posted April 19, 2019 Share Posted April 19, 2019 yes dont use deprecated .exchangeContext() Quote Link to comment Share on other sites More sharing options...
Zappster Posted April 19, 2019 Share Posted April 19, 2019 Maybe read an intro on try + catch statments https://www.w3schools.com/java/java_try_catch.asp Quote Link to comment Share on other sites More sharing options...
Impensus Posted April 19, 2019 Author Share Posted April 19, 2019 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. Quote Link to comment Share on other sites More sharing options...
Impensus Posted April 19, 2019 Author Share Posted April 19, 2019 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. 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. Quote Link to comment Share on other sites More sharing options...
asdttt Posted April 19, 2019 Share Posted April 19, 2019 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); Quote Link to comment Share on other sites More sharing options...