Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Tutorial][Indepth] A better take on task based scripts

Featured Replies

This was a really nice tutorial! Thanks!

 

You did a really great job on your wording and flow through the different components. I already had a basic idea of how to get this going and this tutorial did a fantastic job cementing the ideas around splitting your states into their own classes. Thanks so much for the time you spent on this.

 

As a side note, this really should be Pinned..

  • 9 months later...

Hmm trying to read up on this... How far in Java learning should i be to start using, task based scripts? Intermediate? This is kinda the same thing as a Node system right? 

  • 3 months later...

So if I require the character to withdraw multiple items from the bank, is a task list a good route to get it done?

  • 1 year later...

This was a great tutorial. As a new script writer, I really appreciate a well put-together tutorial like this.
 

Thanks again.

  • 9 months later...
  • 2 weeks later...

Is there a way to have the script stop processing the task list once it matches on of the canProcess() criteria?

 

Currently it keeps trying to process other tasks or at least matching them, but if there are two that qualify it runs them. 

 

For example I have a "Debug" task that I want to use if the script falls through and doesn't match any other canProcess() criteria. But the logs show "I am lost" on every single loop, even it it processes one of the other classes. Is there something that can be added to to "do" part of the class that will make it break out of the current loop and start from the top of the task list?

The java keyword "continue" seems to be what I am looking for but no matter where I put it, Eclipse doesn't like it. Here is my debug class:

 

import org.osbot.rs07.script.MethodProvider;


public class Debug extends Task {

	public Debug(MethodProvider api) {
		super(api);
	}

	@Override
	public boolean canProcess() {
		return !api.myPlayer().isMoving();
	}

	@Override
	public void process() {
		api.log("I am lost");
		
	}

}

 

1 hour ago, sudoinit6 said:

Is there a way to have the script stop processing the task list once it matches on of the canProcess() criteria?

 

Currently it keeps trying to process other tasks or at least matching them, but if there are two that qualify it runs them. 

 

For example I have a "Debug" task that I want to use if the script falls through and doesn't match any other canProcess() criteria. But the logs show "I am lost" on every single loop, even it it processes one of the other classes. Is there something that can be added to to "do" part of the class that will make it break out of the current loop and start from the top of the task list?

The java keyword "continue" seems to be what I am looking for but no matter where I put it, Eclipse doesn't like it. Here is my debug class:

 


import org.osbot.rs07.script.MethodProvider;


public class Debug extends Task {

	public Debug(MethodProvider api) {
		super(api);
	}

	@Override
	public boolean canProcess() {
		return !api.myPlayer().isMoving();
	}

	@Override
	public void process() {
		api.log("I am lost");
		
	}

}

 

use a standard 'for' loop instead of a 'List.forEach' method in main. And you probably want break, not continue.

16 minutes ago, camaro 09 said:

use a standard 'for' loop instead of a 'List.forEach' method in main. And you probably want break, not continue.

Thank you for your response.

My Main class is the same as the one in the first post and I don't see a List.forEach method to change to a for loop.

 

import java.util.ArrayList;

import org.osbot.rs07.script.Script;

public class Main extends Script{

	//this is our array list which will contain our tasks
	ArrayList<Task> tasks = new ArrayList<Task>();
	

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

}

 

1 hour ago, sudoinit6 said:

Thank you for your response.

My Main class is the same as the one in the first post and I don't see a List.forEach method to change to a for loop.

 


import java.util.ArrayList;

import org.osbot.rs07.script.Script;

public class Main extends Script{

	//this is our array list which will contain our tasks
	ArrayList<Task> tasks = new ArrayList<Task>();
	

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

}

 

Read until the end of the first post

21 minutes ago, camaro 09 said:

Read until the end of the first post

DHO! 

 

Thank you again for your time. I will fiddle with that and see if I can make it work.

15 hours ago, camaro 09 said:

Read until the end of the first post

OK, I am a little closer, I changed the loop to this:

 

for (i = 0; i < tasks.size(); i++){
    		x = tasks.get(i);
    		x.run();
    	}

Which works great, now I am having trouble with the "break;". No matter where I put it in the tasks classes I get syntax error or break cannot be used outside of a loop or a switch. Any hints?

1 hour ago, sudoinit6 said:

OK, I am a little closer, I changed the loop to this:

 


for (i = 0; i < tasks.size(); i++){
    		x = tasks.get(i);
    		x.run();
    	}

Which works great, now I am having trouble with the "break;". No matter where I put it in the tasks classes I get syntax error or break cannot be used outside of a loop or a switch. Any hints?

public boolean run() {
  if (canProcess()) {
    process();
    return true;
  }
  return false
}

for (i = 0; i < tasks.size(); i++){
  x = tasks.get(i);
  if (x.run()) {
    break;
  }
}

This will allow you to break the loop and reset whenever a task runs

24 minutes ago, camaro 09 said:

public boolean run() {
  if (canProcess()) {
    process();
    return true;
  }
  return false
}

for (i = 0; i < tasks.size(); i++){
  x = tasks.get(i);
  if (x.run()) {
    break;
  }
}

This will allow you to break the loop and reset whenever a task runs

I came up with something that works but yours is cleaner and I will convert to it. Here is what I did: I declared a static variable "br" in my Task class and added br = 1; to the end of each class. Then I changed my loop to this:

 

int i;
    	Task x;
    	for (i = 0; i < tasks.size(); i++){
    		Task.br = 0;
    		x = tasks.get(i);
    		x.run();
    		if (Task.br == 1) {
    			break;
    		}
 
    	}

 

 

Like I said, yours is better, I just wanted to express that I am trying to learn and not just be spoonfed and I really appreciate your time and help.

  • 3 weeks later...

Sorry I am a total noob coder.
We have this code to add the task in this example:

@Override
public void onStart() {
    tasks.add(new Attack(this));

How do I add another task , for example Banking?
Can I put all name of task in an array list and pass that array list as argument to tasks.add( List here)(this)) ?

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.