Jump to content

Exchanging Context null pointers


Recommended Posts

Posted

Hey all! Still working on my quest bot.

I have a main class script:

private QuestInstance restlessGhost = new RestlessGhost(107);
	
	@SuppressWarnings("deprecation")
	@Override
	public void onStart() throws InterruptedException {
		//cooksAssistant.exchangeContext(getBot());
		restlessGhost.exchangeContext(getBot());
	}
	
	@Override
	public int onLoop() {
		//log("Main loop");
		//log(getConfigs().get(107));
		
		switch(state) {
		case RESTLESS_GHOST:
			((RestlessGhost)restlessGhost).onLoop();
			break;
		default:
			break;
		}
		return 250;
	}

Then there is my abstract QuestInstance class:

public abstract class QuestInstance extends MethodProvider {
  ...
    protected final void speakNPC(String name, String[] options) {
		NPC npc = getNpcs().closest(name);
		
		if (npc != null) {
			if (!getMap().canReach(npc)) {
				if (getDoorHandler().handleNextObstacle(npc)) {
					new ConditionalSleep(3000) {
						
						@Override
						public boolean condition() throws InterruptedException {
							return (!myPlayer().isMoving());
						}
					}.sleep();
				}
			} 
			else {
				if (npc.interact("Talk-to")) {
					new ConditionalSleep(5000) {

						@Override
						public boolean condition() throws InterruptedException {
							return getDialogues().inDialogue();
						}
					}.sleep();
				}
				if (getDialogues().inDialogue()) {
					log("Speaking to aereck...");
					try {
						getDialogues().completeDialogue(options);
					} catch (InterruptedException e) {
						//e.printStackTrace();
					}
				}
			}
		}
	}
}

Now my restless ghost class:

public class RestlessGhost extends QuestInstance {
	...
	String[] dialogueStart = new String[2];
  
    public void onStart() {
		me = getPlayers().myPlayer();

		dialogueStart[0] = "Who's Saradomin?";
		dialogueStart[1] = "Ok, let me help then.";
    }
  	
  	...
      
    private void startQuest() {
      speakNPC("Father Aereck", dialogueStart);
    }
}

Getting a null pointer on my speakNPC function. What is causing this? If I use the exact same function in a single class script it works just fine.

Posted
4 hours ago, Butters said:

Would probably help if you shared the exact error you're getting

He's getting a null pointer exception xD

You can't extend MP. You need to keep an active reference of MP across all classes and then do exchangeContext. I believe this is the only way. extending MP would be great but don't think it can be done.

 

Posted (edited)

Did you possibly forget to call onStart on your RestlessGhost instance? It wont be called automatically.
Also be mindful with initializing it before your Scripts onStart, as accessing hooks before onStart is called will cause errors.

If you share the exact error trace tho, we can help point out exactly where the problem is

11 hours ago, dreameo said:

He's getting a null pointer exception xD

You can't extend MP. You need to keep an active reference of MP across all classes and then do exchangeContext. I believe this is the only way. extending MP would be great but don't think it can be done.

 

Nothing wrong with extending MethodProvider; just remember to exchange contexts.

Edited by FrostBug
  • Like 2
Posted
2 hours ago, FrostBug said:

Did you possibly forget to call onStart on your RestlessGhost instance? It wont be called automatically.
Also be mindful with initializing it before your Scripts onStart, as accessing hooks before onStart is called will cause errors.

If you share the exact error trace tho, we can help point out exactly where the problem is

Nothing wrong with extending MethodProvider; just remember to exchange contexts.

haha i only tried it once before and someone said extending it wont work.

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