Sebastian Posted August 29, 2017 Posted August 29, 2017 (edited) Hi Osbot, My script is freezing when i try to start the cooks assistant quest. Why is this? I have 3 classes: main, gui & cooksassistant. When i select cooks assistant in the gui and press start, the whole client freezes. Main class: import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(author = "Sebastian", info = "All F2P Quests", name = "SB Quester", version = 0, logo = "") public class main extends Script { public String quest = ""; Object lock = new Object(); private gui gui = new gui(); private cooksassistant cooksAssistant = new cooksassistant(); @Override public void onStart() { log("Starting script.."); gui.run(this); } private enum State { COOKSASSISTANT, WAIT }; private State getState() { if (quest == "Cooks Assistant") return State.COOKSASSISTANT; return State.WAIT; } @Override public int onLoop() throws InterruptedException { switch (getState()) { case COOKSASSISTANT: cooksAssistant.run(); break; case WAIT: sleep(random(500, 700)); break; } return random(200, 300); } @Override public void onExit() { log("Goodbye"); } @Override public void onPaint(Graphics2D g) { } } GUI: JComboBox<String> questList = new JComboBox<String>(new String[] { "None", "Cooks Assistant"}); questList.addActionListener(e -> main.quest = (String) questList.getSelectedItem()); Cooksassistant class: import org.osbot.rs07.script.MethodProvider; public class cooksassistant extends MethodProvider { public void run() { log("Talking to Cook"); } } Does someone know what the problem is here? Edited August 29, 2017 by Sebastian
HeyImJamie Posted August 29, 2017 Posted August 29, 2017 (edited) Haven't looked through the code but freezing is normally caused by a null. Check what's in the logger by either leaving it open when starting the script or loading the client via cli and include the -debug command. Edited August 29, 2017 by HeyImJamie
Sebastian Posted August 29, 2017 Author Posted August 29, 2017 11 minutes ago, HeyImJamie said: Haven't looked through the code but freezing is normally caused by a null. Check what's in the logger by either leaving it open when starting the script or loading the client via cli and include the -debug command. Hi Jamie, Thanks for your answer. The problem is that i can't read anything because the logger goes too fast and i can't scroll up since the client is frozen.
IDontEB Posted August 29, 2017 Posted August 29, 2017 17 minutes ago, Sebastian said: Hi Jamie, Thanks for your answer. The problem is that i can't read anything because the logger goes too fast and i can't scroll up since the client is frozen. Your problem I believe is you have to pass the bot's instance to cook's assistant if you want to use log.
Sebastian Posted August 29, 2017 Author Posted August 29, 2017 (edited) 15 minutes ago, IDontEvenBot said: Your problem I believe is you have to pass the bot's instance to cook's assistant if you want to use log. What do you mean? It gives me the error: java.lang.NullPointerException Edited August 29, 2017 by Sebastian
roguehippo Posted August 29, 2017 Posted August 29, 2017 check which line of code the nullpointer is referencing and see what on that line could be uninitialized.
IDontEB Posted August 29, 2017 Posted August 29, 2017 (edited) 30 minutes ago, Sebastian said: What do you mean? It gives me the error: java.lang.NullPointerException Try something along the lines of : replace your onstart and cooksAssistant declaration with this part : private cooksassistant cooksAssistant; @Override public void onStart() { cooksAssistant = new cooksAssistant(this); log("Starting script.."); gui.run(this); } then replace cooksassistant class with the one below and try it public class cooksassistant extends MethodProvider { protected final main S; public cooksassistant(main script) { this.S = script; } public void run() { S.log("Talking to Cook"); } } Edited August 29, 2017 by IDontEvenBot 1
Sebastian Posted August 29, 2017 Author Posted August 29, 2017 I've fixed it! This is how i've done it: I've changed: public class cooksassistant extends MethodProvider { into: public cooksassistant(Script i) throws InterruptedException Now i have to put an 'i' before i use osbot api. Like so: NPC cook = i.npcs.closest("Cook"); cook.interact("Talk-to"); i.log("Talking to Cook"); Not sure how i fixed it but i fixed it lol. 2 minutes ago, IDontEvenBot said: Try something along the lines of : replace your onstart and cooksAssistant declaration with this part : then replace cooksassistant class with the one below and try it Lol, we did the same but different xD 1
IDontEB Posted August 29, 2017 Posted August 29, 2017 9 minutes ago, Sebastian said: I've fixed it! This is how i've done it: I've changed: public class cooksassistant extends MethodProvider { into: public cooksassistant(Script i) throws InterruptedException Now i have to put an 'i' before i use osbot api. Like so: NPC cook = i.npcs.closest("Cook"); cook.interact("Talk-to"); i.log("Talking to Cook"); Not sure how i fixed it but i fixed it lol. Lol, we did the same but different xD Yeah AHA! There used to be exchangeContext(bot) in method provider to do this kind of stuff but its deprecated for some reason. 1
Sebastian Posted August 29, 2017 Author Posted August 29, 2017 Well, @IDontEvenBot I would still like to thank you for your time and effort :). 1