Jump to content

Using multiple classes Object wise for a script


Articron

Recommended Posts

Hi,

 

I'm currently making a combat script.

 

I have divided this script into multiple classes, being Combat.java, Walking.java, Main.java, And various other classes.

 

When I create an object from another class, to use it's methods and everything that comes with it, Osbot just gives me the "error with script executor" error thing.

 

Any help?

Link to comment
Share on other sites

Oh, hahaha, I'm sorry, I should've been more clear in my initial post.

 

Anyway, what I'm trying to explain is the following:

 

Snippet from let's say Altar.java:

 

Combat combat;        public int onLoop() {        try {            useItemsonAltar();            activateAltar();            combat.killCow();        } catch (InterruptedException e) {            log("nope werkt ni!");            e.printStackTrace();        }        return 1;    }

 

The method it's refering to in Combat.java:

 

 

public void killCow() throws InterruptedException {        sleep(3000);        unicow = closestNPC(UNICOW_ID);        if (unicow != null && !unicow.isUnderAttack())            unicow.interact("Attack",true,true);        while (client.getClient().getMyPlayer().isUnderAttack()) {            log("currently under attack: " + Boolean.toString(client.getClient().getMyPlayer().isUnderAttack()));            sleep(5000);        }        lootHorns();    }

 

It seems that it has trouble trying to call that method from another class, even though I tried a fake constructor, or anything amongst the sorts.

 

My IDE doesn't show up any errors, let alone that I think I made a mistake, OsBot itself just won't execute the killCow method, and will skip it to repeat the onLoop().

Edited by Articron
Link to comment
Share on other sites

Use Script class in the other classes so for example. You main script class is called CombatScript.java and it extends Script.

 

Make a new class called Combat which take a parameter of type Script to be able to use all the script methods

it will look something like this:

public class Combat {	public Combat(Script script) {		this.script = script;        }	public void attack() {				script.client..//etc		bla bla bla        }	public Script getScript() {		return script;	}	private Script script;}

 

and In onStart method in your main class you do something like

 

Combat combat = new Combat(this);

 

by this, you passed the script object(your main class) to your combat class and avoid getting null exception

 

now you can call any method of the combat class such as

combat.attack();

Hope you understand.. im bad at explaining.

if you need anything feel free to ask

 

Edited by Wiz
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...