Jump to content

Methods Template?


investmentideas

Recommended Posts

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();
    }
}
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
}

 

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