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.

Multiple classes :doge:

Featured Replies

Alright so, I looked at quite a few tutorials, read quite a few posts and i'm still a tad confused.

 

I have a main class and then I have other classes.

If I'm trying to use methods in my secondary class, it tends to null out, even though methods are available.

 

Halp pls

package AIO;

public class wc extends AIORuneScape{

	int abc = 5;

	public void Woodcutting() throws InterruptedException {
		sleep(500);
		if (npcs.closest("Banker") != null) {
			log("test");
		}
	}

}

This is the secondary class.

In order to access OSBot fields and methods you must have a valid Script instance reference which must also be the instance you happen to be defining as your main class. I suggest you pass it as a parameter to the constructor of each class and store it in a non-static field. Then you can instantiate the class from your main class, passing the main class as a reference for your other classes to use in order to access OSBot methods and fields.

If you are getting a NPE it's either because the object returns null (non-existent or out of index range) or you aren't properly initializing the API for other classes.

 

To elaborate on the post above:

public class Secondary extends ScriptNode {

    private API api;
    
    public Second(API api) {
        this.api = api;
  }
}

Edited by Bitshift

  • Author

In order to access OSBot fields and methods you must have a valid Script instance reference which must also be the instance you happen to be defining as your main class. I suggest you pass it as a parameter to the constructor of each class and store it in a non-static field. Then you can instantiate the class from your main class, passing the main class as a reference for your other classes to use in order to access OSBot methods and fields.

pF9L7A7.png

  • Author

You're making an AIO RS without understanding/usage of OOP here?

I understand OOP, I don't understand multiple classes.

I understand OOP, I don't understand multiple classes.

 

One of the pinnacles of OOP is polymorphism, which by definition, will result in multiple classes.

  • Author

One of the pinnacles of OOP is polymorphism, which by definition, will result in multiple classes.

Well, it's a good thing I have this here thread for that there point you're making.

 

And 'one of'.

Saying I know about Java doesn't necessarily imply I can list every single function and know exactly what to do in every situation without outside assistance either.

I still don't fully understand what you're trying to do.

 

Are you trying to access wc methods from AIORunescape?

 

so wc w = new wc();

wc.woodcut();

?

 

That's what I see it as rn.

  • Author

I still don't fully understand what you're trying to do.

 

Are you trying to access wc methods from AIORunescape?

 

so wc w = new wc();

wc.woodcut();

?

 

That's what I see it as rn.

trying to call the woodcutting class from main script once it's needed

then use shit like players.myplayer and so forth in the woodcutting class itself

Let me elaborate the post I made earlier since I couldnt post code from my phone.

 

Main.Java

package somePackage;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;


@ScriptManifest(name = "AIO Runescape", author = "JohnnyDepp", version = 6.9, info = "Unicorns", logo = "")
public class Main extends Script {

    Woodcutting wc;

    @Override
    public void onStart() {
        wc = new Woodcutting(this);
    }

    @Override
    public int onLoop() {
        wc.cutTree();
        return 100;
    }

}

Woodcutting.Java

package somePackage;

public class Woodcutting {

    Main main;

    public Woodcutting(Main mainReference) {
        this.main = mainReference;
    }

    public void cutTree() {
        main.log("Time to cut some shit");
        // insert actual code
    }

}

The above code should spam your logger with "Time to cut some shit".

 

Edited by Token

  • Author

Let me elaborate the post I made earlier since I couldnt post code from my phone.

 

Main.Java

package somePackage;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;


@ScriptManifest(name = "AIO Runescape", author = "JohnnyDepp", version = 6.9, info = "Unicorns", logo = "")
public class Main extends Script {

    Woodcutting wc;

    @Override
    public void onStart() {
        wc = new Woodcutting(this);
    }

    @Override
    public int onLoop() {
        wc.cutTree();
        return 100;
    }

}

Woodcutting.Java

package somePackage;

public class Woodcutting {

    Main main;

    public Woodcutting(Main mainReference) {
        this.main = mainReference;
    }

    public void cutTree() {
        main.log("Time to cut some shit");
        // insert actual code
    }

}

The above code should spam your logger with "Time to cut some shit".

thanks bae, this worked perfectly

Let me elaborate the post I made earlier since I couldnt post code from my phone.

 

Main.Java

package somePackage;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;


@ScriptManifest(name = "AIO Runescape", author = "JohnnyDepp", version = 6.9, info = "Unicorns", logo = "")
public class Main extends Script {

    Woodcutting wc;

    @Override
    public void onStart() {
        wc = new Woodcutting(this);
    }

    @Override
    public int onLoop() {
        wc.cutTree();
        return 100;
    }

}

Woodcutting.Java

package somePackage;

public class Woodcutting {

    Main main;

    public Woodcutting(Main mainReference) {
        this.main = mainReference;
    }

    public void cutTree() {
        main.log("Time to cut some shit");
        // insert actual code
    }

}

The above code should spam your logger with "Time to cut some shit".

package trumpbitch;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import trumpbitch.Woodcutting;

@ScriptManifest(name = "trumpscape", author = "trump", version = 6.9, info = "trump", logo = "trump")
public class Main extends Script {

    @Override
    public void onStart() {
        // nothing cause trump
    }

    @Override
    public int onLoop() {
        Woodcutting.cutTree(this);
        return 100;
    }

}
package trumpbitch;

import org.osbot.rs07.script.Script;

public class Woodcutting {

    public static boolean cutTree(Script script) {
        script.log("trump for pres");
        // insert just the tip
        return false;
    }

}

this way is pretty much the same thing but i find it's easier to copy paste to new scripts this way. good luck

 

Edited by Shiny

Create an account or sign in to comment

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.