Jump to content

Methods Template?


Recommended Posts

Posted

I was wondering if anyone had a barebones methods template? Kind of similar to the one I have created below? I am looking at implementing methods now instead of placing everything in a single loop.

 

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

@ScriptManifest(name = "", logo = "", version = 1.0, author ="", info ="")
public class test extends Script {


    @Override
    public void onStart() throws InterruptedException {
        super.onStart();
    }

    @Override
    public int onLoop() throws InterruptedException {
        return 0;
    }

    @Override
    public void onExit() throws InterruptedException {
        super.onExit();
    }
}
Posted

How I go about it is like this:

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


@ScriptManifest(name = "Example", logo = "", version = 1, author = "Your name here", info = "Example script")



public class Example extends Script {
    
    private void exampleMethod() {
        // Put your method in here and call in the onLoop with conditions
    }
    
    
    
    
    @Override
    public int onLoop() throws InterruptedException {
        // if(Im where I need to be) { <--- Condition to run method
        // exampleMethod(); <--- Method is executed if condition met
        return 0;
    }
}

Not saying this is the "proper" OR best way to go about it but works for me. Have only used this for the simplest of tasks though. For more complex scripts I'm sure there's far better ways to structure it. 

Hope this helps.

Posted

I personally use a mix between a Task and a State 'framework'

For example, I'll have a Bank Task which contains code for banking. And in that class will be a switch statement that chances based on certain conditions, for example:

switch (getTaskState()) {
	case WALK_TO_BANK:
		// walk to bank etc
		break;

	case OPEN_BANK:
		// open bank
		break;

	// etc
}

private enum TaskState {
	WALK_TO_BANK,
	OPEN_BANK,
	BANK_ETC
}

private TaskState getTaskState() {
	if (!Bank.contains(Player)) {
		return TaskState.WALK_TO_BANK;
	
	// etc
}

 

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