Jump to content

Multiple classes :doge:


Salty as fuck

Recommended Posts

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.

Link to comment
Share on other sites

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.

  • Like 3
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
  • Like 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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