Jump to content

multiple classes?


Recommended Posts

Posted

Can I use multiple classes for a script? What I essentially want to do it do a task until a condition is met, and then perform a different task, within a different java class in the same script.

is this possible? and if so, how do I switch to the next class within my code? 

Sorry about the question, i'm a java noob xD

Posted (edited)

heres the 2 ways to do mutiple classes. I know there are more but these are simple.

Type 1:

public class Something extends MethodProvider {
	public void doSomething(){
		getBank().Open()
	}
}

in your main script do this

Something something = new Something()

void onStart(){
        something.exchangeContext(getBot());
}

Type 2:

public class Something{
	MethodProvider mp;
	public Something(MethodProvider mp){
		this.mp =mp
	}
	public void doSomething(){
		mp.getBank().Open()
	}

}

 

REad your question wrong this is something you like

Just warning scripts write like this are hard to debug and pron to errors

 

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

public abstract  class Test extends MethodProvider {
    abstract void doSomething();
    abstract  boolean done();
    abstract Test next();


}


public   class OpenBank extends Test {


    @Override
    void doSomething() {
        try {
            this.getBank().open();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    boolean done() {
        return getBank().isOpen();
    }

    @Override
    Test next() {
        return new CloseBank();
    }
}
public   class CloseBank extends Test {


    @Override
    void doSomething() {

            this.getBank().close();

    }

    @Override
    boolean done() {
        return !getBank().isOpen();
    }

    @Override
    Test next() {
        return new OpenBank();
    }
}

@ScriptManifest(author = "Bacon", name = "0", info = "Runtime bots", version = 0.0, logo = "")

public class ScriptWithtasks extends Script {
    Test curent = new OpenBank();

    @Override
    public void onStart() throws InterruptedException {
        curent.exchangeContext(getBot());

    }

    @Override
    public int onLoop() throws InterruptedException {
        curent.doSomething();

        if (curent.done()){
            curent = curent.next();
            curent.exchangeContext(getBot());
        }

        return 0;
    }
}

 

 

 

 

Irl ProjectPact be like...

Random person: Someone call 911.

ProjectPact: You should try Script Factory :) 

 

 

 

 

 

Edited by Nbacon
  • Like 1
Posted
4 hours ago, Gunman said:

Money hungry Project didn't answer the question. Answer is yes you can. Read everything in OOP 1 & 2 and I think that would be enough to start messing around with multiple classes.

EDIT: Forgot to link the material https://www.programiz.com/java-programming

Or trying to help someone with a tool that is designed to develop scripts with no programming knowledge. 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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