Jump to content

Script makes Osbot freeze


Sebastian

Recommended Posts

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

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.

Link to comment
Share on other sites

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 by IDontEvenBot
  • Like 1
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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. 

  • Like 1
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...