Jump to content

having trouble script wont even start running


kyukyu

Recommended Posts

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

Link to comment
Share on other sites

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
  • Like 1
Link to comment
Share on other sites

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)

    }

}

 

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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