February 20, 20178 yr Hi, I tried accessing a method from class Fletch in class main. IntelliJ doesn't give any error but when I try to run it in OSBot it will spam errors with NullPointerException in the console. import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(name = "Testscript", author = "Test", version = 1.0, info = "", logo = "") public class main extends Script { @Override public void onStart() { //Code here will execute before the loop is started } @Override public void onExit() { //Code here will execute after the script ends } @Override public int onLoop() { Fletch fletch = new Fletch(); fletch.FletcherLoop(); return 1000; //The amount of time in milliseconds before the loop starts over } @Override public void onPaint(Graphics2D g) { //This is where you will put your code for paint(s) } } public class Fletch extends main { public void FletcherLoop() { log("This is my fletch loop"); } } I created a fresh script so I don't have to post all my lines of my original script. It's still giving me the same error.
February 20, 20178 yr It's because you're extending your class called main. Consider reading up on inheritance
February 20, 20178 yr Author 6 minutes ago, Explv said: It's because you're extending your class called main. Consider reading up on inheritance I know what inheritance is. When i don't extend it, I have to extend it with Script which will ask for an onLoop method. That's not really what I want.
February 20, 20178 yr 3 minutes ago, The Undefeated said: I know what inheritance is. When i don't extend it, I have to extend it with Script which will ask for an onLoop method. That's not really what I want. Or just pass a MethodProvider reference to the constructor of your class (your main class extends MethodProvider) so that you can access the API methods Another alternative is to extend MethodProvider and call exchangeContext(Bot bot) Edited February 20, 20178 yr by Explv
February 20, 20178 yr public class Fletch extends main { public void FletcherLoop() { log("This is my fletch loop"); } } public class Fletch { private MethodProvider ctx; public Fletch(MethodProvider ctx){ this.ctx = ctx; } public void FletcherLoop() { ctx.walk ctx.log("This is my fletch loop"); } } //inmain Fletch fletch = new Fletch(this); fletch.loop() u tryna do something like dis? Edited February 20, 20178 yr by Chris
February 20, 20178 yr Author 41 minutes ago, Explv said: Or just pass a MethodProvider reference to the constructor of your class (your main class extends MethodProvider) so that you can access the API methods Another alternative is to extend MethodProvider and call exchangeContext(Bot bot) It's not clear to me what you are trying to explain. Extending the Fletch class with MethodProvider will result in the same errors. Edit: My bad gives another error, give me a minute to check. Edited February 20, 20178 yr by The Undefeated
February 20, 20178 yr 3 minutes ago, The Undefeated said: It's not clear to me what you are trying to explain. Extending the Fletch class with MethodProvider will result in the same errors. Yes but there is a method exchangeContext(Bot bot) which in simple terms basically copies all the variables from the bot instance to your class. Which would fix your Null pointer exception. Fletch fletch = new Fletch(); fletch.exchangeContext(getBot()); Edited February 20, 20178 yr by Explv
February 20, 20178 yr Author 6 minutes ago, Explv said: Yes but there is a method exchangeContext(Bot bot) which in simple terms basically copies all the variables from the bot instance to your class. Which would fix your Null pointer exception. Fletch fletch = new Fletch(); fletch.exchangeContext(getBot()); Got it working, thanks!