Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Accessing method from another class

Featured Replies

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.

 

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

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 by Explv

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 by Chris

  • 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 by The Undefeated

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 by Explv

  • 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!

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.