Jump to content

Script not running


Magerange

Recommended Posts

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

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 

Link to comment
Share on other sites

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);
    	}
    }
    }

 

Link to comment
Share on other sites

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

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

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?

Link to comment
Share on other sites

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