Jump to content

Exchanging Context null pointers


Athylus

Recommended Posts

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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

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.

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