Jump to content

Debugging error in onStart()?


Recommended Posts

Posted

What's the general rule of thumb at debugging scripts?

 

What I do is

 

- realize it's buggy

- log out of client

- rewrite one line

- recompile

- copy to scripts folder

- relauch client

- log in to account manually

- start script

- GOTO 1;

 

It takes more than a minute.

 

I'm getting a mysterious error in onStart() and I can locate which method causes it. I can't get a clearer error message though. The error must be that widget child/grandchild IDs do not always match, and cant't figure out why.

 

Posted (edited)

What's the general rule of thumb at debugging scripts?

 

What I do is

 

- realize it's buggy

- log out of client

- rewrite one line

- recompile

- copy to scripts folder

- relauch client

- log in to account manually

- start script

- GOTO 1;

 

It takes more than a minute.

 

I'm getting a mysterious error in onStart() and I can locate which method causes it. I can't get a clearer error message though. The error must be that widget child/grandchild IDs do not always match, and cant't figure out why.

 

are you null checking them? post the code

Edited by Precise
Posted

You don't have to relaunch the client. Configure an artifact (or w/e it's called in your IDE) in the script folder and your IDE will replace it after each compilation. So all you have to do is refresh and restart the script.

I think it's possible to just catch any exception in onStart and print its message.

try {

....

} catch(Exception e) {
 if(e.getMessage() != null) log(e.getMessage());

}

Posted (edited)

I'll google for this artifact stuff.

 

Here's the current messy code.

	public int getPriceOnTheRight() throws InterruptedException{

		RS2Widget rightside = widgets.get(465, 23, 39);
		
		if(rightside != null){

			// log(rightside.getMessage()); 
                        // maybe this has no getMessage method, how to check this?

			String msg = rightside.getMessage(); // the error is thrown here I guess

			if(msg != null){
				return Integer.parseInt(msg.replace(" coins", ""));
			}else{
				log("getMessage didnt find any text");
				return 0;
			}
			
		}else{
			log("Right side widget area not found");
			return 0;
		}

	}
Edited by casual
Posted

What's the general rule of thumb at debugging scripts?

 

I'm getting a mysterious error in onStart() and I can locate which method causes it. I can't get a clearer error message though. The error must be that widget child/grandchild IDs do not always match, and cant't figure out why.

put a log between each line and see which line was last called. Anything under that is where the problem is coming from

Posted (edited)

As others have said wrap your onStart method in a try catch statement.

 

You could print the track stace like;


	try {
	
		/* YOUR CODE HERE */

	} catch(final Exception e) {
		final StackTraceElement[] stack = e.getStackTrace();
		for (final StackTraceElement ste : stack)
			log(ste.getMessage());
	}
	

The only area I can see any error potentially being thrown there is your Integer.parseInt, make sure that the text doesn't have trailing or leading whitespace, you can use .trim() to ensure that.

 

Also, print it out to see what it's actually trying to parse to ensure it's not going to throw a NumberFormatException.

Edited by Zee Best

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...