Jump to content

Call other script/class from inside script?


Recommended Posts

Posted (edited)

Having an issue where it just crashes the bot.

Just trying to get it set up, so there isn't much code, but the gist is like this:

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

import skills.Fishing;

@ScriptManifest(name = "Testing", author = "Aeikonic", info = "Just a test", version = 0.1, logo = "")
public class testBot extends Script {

    protected Fishing fish;

    @Override
    public final int onLoop() throws InterruptedException {
        fish.goFishing();
        return random(150, 200);
    }
}

The fishing script is declared like this:

public abstract class Fishing extends Script {

Is that the issue or is it how I'm calling it in the upper level script? The fishing bot works when turned into a normal script. How do I call it / activate it from another script?

 

EDIT:

 

Updated Fishing to an Event:

public class Fishing extends Event {

Calling it like this:

protected Fishing fish = new Fishing();

@Override
public final int onLoop() throws InterruptedException {
    fish.execute();
    return random(150, 200);
}

Getting a NullPointerException though which says it's at this line:

private boolean canFish() {
    return getInventory().contains("Small fishing net");
}

Wasn't getting it when not pulling the script in as an event though, so a bit confused... not sure if I'm still pulling it in wrong or if running it as an event means I need to recode parts of it.

 

EDIT AGAIN:

Got it, had to run execute(fish);

:)

Edited by aeikonic
Posted (edited)

I'd recommend following some Java tutorials, in your first example you didn't even construct an instance of your Fishing class. You also made your Fishing class abstract, which means it cannot be instantiated directly.

Only your main script class should extend Script.

If you want other classes to be able to access the API, either pass MethodProvider as a constructor arg, or make your other class extend MethodProvider and exchange context.

See section 5 of https://osbot.org/forum/topic/115124-explvs-scripting-101/

 

 

Edited by Explv
Posted

Yeah the IDE was throwing me for a loop because it told me if I didn't have onLoop in Fishing (when it was extending Script) I'd have to make it abstract, which then told me I couldn't instantiate it on the upper level script. Had me all confused but figured it out. Got a few basic scripts working now though :D

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