Jump to content

Script not running


Recommended Posts

Posted (edited)

So I wrote a local script with Eclipse and tried to export it as a .jar file to run it.

The problem is that it does not start. When I select it in OSBot, it does nothing.

My guess is that it has something to do with JRE versions not mathcing (1.7 compared to 1.8), but since I am a newbie with this, maybe someone can take me through how to check this propertly...?
Should I just clean my PC from Java and install JRE 1.7?

Much appreciated <3

Edited by Magerange
Posted

You most likely attempted to initialize an instance of any OSBot class outside the methods defined in the Script class, eg:

@ScriptManifest(name = "Lol", author = "Token", version = 1.0, info = "", logo = "")
public class Lol extends Script {
	
  NPC x = npcs.closest("Guard"); // script won't start because of this
  NPC y;
  
  @Override
  public void onStart() throws InterruptedException {
    // something 
    y = npcs.closest("Guard"); // but this is fine
  }
  
  @Override
  public int onLoop() throws InterruptedException {
    // something 
    return 69;
  }
  
}

Post your code if that's not the case because this is definitely a programming error 

Posted
10 minutes ago, Token said:

You most likely attempted to initialize an instance of any OSBot class outside the methods defined in the Script class, eg:


@ScriptManifest(name = "Lol", author = "Token", version = 1.0, info = "", logo = "")
public class Lol extends Script {
	
  NPC x = npcs.closest("Guard"); // script won't start because of this
  NPC y;
  
  @Override
  public void onStart() throws InterruptedException {
    // something 
    y = npcs.closest("Guard"); // but this is fine
  }
  
  @Override
  public int onLoop() throws InterruptedException {
    // something 
    return 69;
  }
  
}

Post your code if that's not the case because this is definitely a programming error 

Alright, so here is what I've been working on:

@ScriptManifest(author = "Magerange", name = "JugFiller", info = "Fills jugs with water in east Falador", version = 1.0, logo = "")
public final class Main extends Script  {

	private final Area Pump = new Area (2947, 3382, 2948, 3383);

@Override
    public final int onLoop() throws InterruptedException {
 if (canFill()){
	 fill();
 } else {
	 bank();
 }
 return random(175, 270);
    }
    
private boolean canFill() {
	return getInventory().contains("Jug");
}
private boolean pumpUsable(){
	return Pump.contains(myPlayer());
}

Entity wPump = getObjects().closest("Waterpump");

private void fill() {
	if (!Pump.contains(myPosition())){
		getWalking().webWalk(Pump);
	} else if (pumpUsable()) {
		if (wPump != null)
	inventory.interact("Use","Jug");
		wPump.interact("Use");
	} else {
		new ConditionalSleep(1500) {
			@Override
			public boolean condition() {
				return myPlayer().isAnimating();
			}
		}.sleep();
	}
}

	private void bank() throws InterruptedException {
    	if(!Banks.FALADOR_EAST.contains(myPosition())) {
    		getWalking().webWalk(Banks.FALADOR_EAST);
    	} else if (!getBank().isOpen()) {
    		getBank().open();
    	} else if (!getInventory().isEmptyExcept("Jug")) {
    		getBank().depositAll();
    	} else if (getBank().contains("Jug")) {
    		getBank().withdrawAll("Jug");
    	} else  {
    		stop(true);
    	}
    }
    }

 

Posted
4 minutes ago, Magerange said:

Alright, so here is what I've been working on:


@ScriptManifest(author = "Magerange", name = "JugFiller", info = "Fills jugs with water in east Falador", version = 1.0, logo = "")
public final class Main extends Script  {

	private final Area Pump = new Area (2947, 3382, 2948, 3383);

@Override
    public final int onLoop() throws InterruptedException {
 if (canFill()){
	 fill();
 } else {
	 bank();
 }
 return random(175, 270);
    }
    
private boolean canFill() {
	return getInventory().contains("Jug");
}
private boolean pumpUsable(){
	return Pump.contains(myPlayer());
}

Entity wPump = getObjects().closest("Waterpump");

private void fill() {
	if (!Pump.contains(myPosition())){
		getWalking().webWalk(Pump);
	} else if (pumpUsable()) {
		if (wPump != null)
	inventory.interact("Use","Jug");
		wPump.interact("Use");
	} else {
		new ConditionalSleep(1500) {
			@Override
			public boolean condition() {
				return myPlayer().isAnimating();
			}
		}.sleep();
	}
}

	private void bank() throws InterruptedException {
    	if(!Banks.FALADOR_EAST.contains(myPosition())) {
    		getWalking().webWalk(Banks.FALADOR_EAST);
    	} else if (!getBank().isOpen()) {
    		getBank().open();
    	} else if (!getInventory().isEmptyExcept("Jug")) {
    		getBank().depositAll();
    	} else if (getBank().contains("Jug")) {
    		getBank().withdrawAll("Jug");
    	} else  {
    		stop(true);
    	}
    }
    }

 

It's exactly what I said, you initialized wPump outside the Script methods

  • Like 1
Posted
10 minutes ago, Magerange said:

Alright, so here is what I've been working on:


@ScriptManifest(author = "Magerange", name = "JugFiller", info = "Fills jugs with water in east Falador", version = 1.0, logo = "")
public final class Main extends Script  {

	private final Area Pump = new Area (2947, 3382, 2948, 3383);

@Override
    public final int onLoop() throws InterruptedException {
 if (canFill()){
	 fill();
 } else {
	 bank();
 }
 return random(175, 270);
    }
    
private boolean canFill() {
	return getInventory().contains("Jug");
}
private boolean pumpUsable(){
	return Pump.contains(myPlayer());
}

Entity wPump = getObjects().closest("Waterpump");

private void fill() {
	if (!Pump.contains(myPosition())){
		getWalking().webWalk(Pump);
	} else if (pumpUsable()) {
		if (wPump != null)
	inventory.interact("Use","Jug");
		wPump.interact("Use");
	} else {
		new ConditionalSleep(1500) {
			@Override
			public boolean condition() {
				return myPlayer().isAnimating();
			}
		}.sleep();
	}
}

	private void bank() throws InterruptedException {
    	if(!Banks.FALADOR_EAST.contains(myPosition())) {
    		getWalking().webWalk(Banks.FALADOR_EAST);
    	} else if (!getBank().isOpen()) {
    		getBank().open();
    	} else if (!getInventory().isEmptyExcept("Jug")) {
    		getBank().depositAll();
    	} else if (getBank().contains("Jug")) {
    		getBank().withdrawAll("Jug");
    	} else  {
    		stop(true);
    	}
    }
    }

 

As Token said; I'd move the initialization of wPump to the fill() method.

  • Like 1
Posted

Thanks to both of you! It works now. However, I have found out that my conditionalsleep does not function propertly. I think I have set wrong parameter for it, because the account doesn't always animate while filling jugs.

How could I replace it so it sleeps for x miliseconds? Do I have to change a lot of code?

Posted (edited)

If there is an error before the onStart method is called it will simply not log the error and leave you clueless. Make sure there is no code executing before the onStart method that accesses any osbot library, such as during variable initialization. It's simply throwing NPE and suppressing the error..

Not your fault, bad programming on the APIs part not logging those exceptions. 

Edited by dmmslaver

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