Jump to content

My script won't start


Recommended Posts

Posted

Hello,

So I've been watching a YouTube video and looking at the tutorials posted on the forums on creating my first script.

I'm trying to run a test like the video, when it first ran it's test, but when I attempt to run my code, nothing happens.

 

and here's the code, it's not exactly like the video, but I don't see the problem with when I try to run it.

 


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

import java.awt.Graphics2D;

import org.osbot.rs07.api.Inventory;
import org.osbot.rs07.api.model.NPC;

@ScriptManifest(author = "Kingbutton", name = "Shrimp Catcher", info = "Catches shrimp at Draynor Village", version = 0.1, logo = "")
public final class Main extends Script {

    NPC spot = npcs.closest("Fishing spot");

    @Override
    public void onStart() {
        log("You have activated Shrimp Catcher!");
    }

    @Override
    public final int onLoop() throws InterruptedException {

        if (!inventory.isFull()) {

            // fishes
            if (spot != null) {
                if (spot.isVisible()) {
                    //if() adding this later.
                    spot.interact("Net");
                } else {
                    // else statement
                    camera.toEntity(spot);
                }
            }
        }
        return 50;
    }

    public void onExit() {
        log("Thanks for using Shrimp Catcher!");
    }

    @Override
    public void onPaint(Graphics2D g) {
        // gui

    }

}

Posted
2 hours ago, kingbutton said:

Nice it works! Can you explain to me I need to put that line of code there though?

Cause the first thing OSBot does is do stuff in onStart() method, then loops your logic in onLoop() method. You fetch the fishing spot only when the class is initialized (which will be null).

You want to find your npcs in the onLoop() method.  

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