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.

having trouble script wont even start running

Featured Replies

package Main;

import org.osbot.rs07.script.Script;

import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.*;
import org.osbot.rs07.api.map.Position;

import java.awt.*;

@ScriptManifest(name = "CrabKiller", author = "kyu", version = 1.0, info = "noob scripting", logo = "") 

public class Main extends Script {

 

	   @Override
    public void onStart() {

    	log("welcome to  kyu crabs");
        //Code here will execute before the loop is started

    }
    
    private enum State{
    	FIGHTING, RESET;
    }
    private State getState(){
    	if(myPlayer().isHitBarVisible() || myPlayer().isUnderAttack())
    		return State.FIGHTING;
    	return State.RESET;
    }

    @Override

    public void onExit() {
    	log("ending....");
        //Code here will execute after the script ends

    }
	final Position starting = myPlayer().getPosition();
	final Position reset = new Position(1750,3503,0);

	@Override
    public int onLoop() throws InterruptedException{
    	switch(getState()){
    	case FIGHTING:
    		if(myPlayer().getHealthPercent()<50)
    			getInventory().interact("Eat","Tuna");
    		return 20000;
    	case RESET:
    		log("walking....");
    		getWalking().walk(reset);
    		sleep(15000);
    		log("walking to start");
    		getWalking().walk(starting);
    		sleep(15000);
    	}
    	
        return 5000; //The amount of time in milliseconds before the loop starts over

    }

    @Override

    public void onPaint(Graphics2D g) {

        //This is where you will put your code for paint(s)

    }

}

I was building a simple afk sandcrabber for personal use but when i went to test it wouldnt even start running. The logger doesnt even show the onstart text so i'm looking for a quick troubleshoot

3 hours ago, kyukyu said:

package Main;

import org.osbot.rs07.script.Script;

import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.*;
import org.osbot.rs07.api.map.Position;

import java.awt.*;

@ScriptManifest(name = "CrabKiller", author = "kyu", version = 1.0, info = "noob scripting", logo = "") 

public class Main extends Script {

 

	   @Override
    public void onStart() {

    	log("welcome to  kyu crabs");
        //Code here will execute before the loop is started

    }
    
    private enum State{
    	FIGHTING, RESET;
    }
    private State getState(){
    	if(myPlayer().isHitBarVisible() || myPlayer().isUnderAttack())
    		return State.FIGHTING;
    	return State.RESET;
    }

    @Override

    public void onExit() {
    	log("ending....");
        //Code here will execute after the script ends

    }
	final Position starting = myPlayer().getPosition();
	final Position reset = new Position(1750,3503,0);

	@Override
    public int onLoop() throws InterruptedException{
    	switch(getState()){
    	case FIGHTING:
    		if(myPlayer().getHealthPercent()<50)
    			getInventory().interact("Eat","Tuna");
    		return 20000;
    	case RESET:
    		log("walking....");
    		getWalking().walk(reset);
    		sleep(15000);
    		log("walking to start");
    		getWalking().walk(starting);
    		sleep(15000);
    	}
    	
        return 5000; //The amount of time in milliseconds before the loop starts over

    }

    @Override

    public void onPaint(Graphics2D g) {

        //This is where you will put your code for paint(s)

    }

}

I was building a simple afk sandcrabber for personal use but when i went to test it wouldnt even start running. The logger doesnt even show the onstart text so i'm looking for a quick troubleshoot

 

You are making API calls before onStart() is called. You can't do that, as the API has not been setup yet.

Move this code that is currently above onLoop:

final Position starting = myPlayer().getPosition();

Inside of onStart() or onLoop().

Or if it needs to be a global variable, declare it globally:

Position starting;

Then initialise it in onStart()

starting = whatever

Sorry about formatting, on phone.

 

Edited by Explv

  • Author

how would i declare the variable globally so that it can be called from in the onloop method?

4 minutes ago, kyukyu said:

how would i declare the variable globally so that it can be called from in the onloop method?

package Main;

import org.osbot.rs07.script.Script;

import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.*;
import org.osbot.rs07.api.map.Position;

import java.awt.*;

@ScriptManifest(name = "CrabKiller", author = "kyu", version = 1.0, info = "noob scripting", logo = "") 

public class Main extends Script {

 	private final Position starting, reset;

	   @Override
    public void onStart() {
		starting = myPlayer().getPosition();
        reset = new Position(1750,3503,0);
    	log("welcome to  kyu crabs");
        //Code here will execute before the loop is started

    }
    
    private enum State{
    	FIGHTING, RESET;
    }
    private State getState(){
    	if(myPlayer().isHitBarVisible() || myPlayer().isUnderAttack())
    		return State.FIGHTING;
    	return State.RESET;
    }

    @Override

    public void onExit() {
    	log("ending....");
        //Code here will execute after the script ends

    }

	@Override
    public int onLoop() throws InterruptedException{
    	switch(getState()){
    	case FIGHTING:
    		if(myPlayer().getHealthPercent()<50)
    			getInventory().interact("Eat","Tuna");
    		return 20000;
    	case RESET:
    		log("walking....");
    		getWalking().walk(reset);
    		sleep(15000);
    		log("walking to start");
    		getWalking().walk(starting);
    		sleep(15000);
    	}
    	
        return 5000; //The amount of time in milliseconds before the loop starts over

    }

    @Override

    public void onPaint(Graphics2D g) {

        //This is where you will put your code for paint(s)

    }

}

 

  • Author

update: fixed have a fully functioning afk sandcrab script :)

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.