kyukyu Posted October 9, 2017 Share Posted October 9, 2017 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 Quote Link to comment Share on other sites More sharing options...
Explv Posted October 9, 2017 Share Posted October 9, 2017 (edited) 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 October 9, 2017 by Explv 1 Quote Link to comment Share on other sites More sharing options...
kyukyu Posted October 9, 2017 Author Share Posted October 9, 2017 how would i declare the variable globally so that it can be called from in the onloop method? Quote Link to comment Share on other sites More sharing options...
HunterRS Posted October 9, 2017 Share Posted October 9, 2017 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) } } Quote Link to comment Share on other sites More sharing options...
kyukyu Posted October 9, 2017 Author Share Posted October 9, 2017 update: fixed have a fully functioning afk sandcrab script Quote Link to comment Share on other sites More sharing options...