Jump to content
mitsuki

multiple classes?

Recommended Posts

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

Link to post
Share on other sites
8 minutes 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

Thank you dude!

Link to post
Share on other sites

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

Link to post
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.

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