Jump to content

Call other script/class from inside script?

Recommended Posts

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;

    public final int onLoop() throws InterruptedException {
        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?




Updated Fishing to an Event:

public class Fishing extends Event {

Calling it like this:

protected Fishing fish = new Fishing();

public final int onLoop() throws InterruptedException {
    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.



Got it, had to run execute(fish);


Edited by aeikonic
Link to post
Share on other sites

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

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

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.

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