Athylus Posted April 15, 2018 Share Posted April 15, 2018 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. Quote Link to comment Share on other sites More sharing options...
Butters Posted April 15, 2018 Share Posted April 15, 2018 Would probably help if you shared the exact error you're getting Quote Link to comment Share on other sites More sharing options...
dreameo Posted April 15, 2018 Share Posted April 15, 2018 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. Quote Link to comment Share on other sites More sharing options...
FrostBug Posted April 16, 2018 Share Posted April 16, 2018 (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 April 16, 2018 by FrostBug 2 Quote Link to comment Share on other sites More sharing options...
dreameo Posted April 16, 2018 Share Posted April 16, 2018 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. Quote Link to comment Share on other sites More sharing options...
Athylus Posted April 16, 2018 Author Share Posted April 16, 2018 Thanks FrostBug! I thought onStart would be called automatically. So I called it after exchange context and it's working just fine now. Quote Link to comment Share on other sites More sharing options...