Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Exchanging Context null pointers

Featured Replies

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.

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

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.

 

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

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.

  • Author

Thanks FrostBug! I thought onStart would be called automatically. So I called it after exchange context and it's working just fine now.

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.