Jump to content

Debugging error in onStart()?


casual

Recommended Posts

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.

 

Link to comment
Share on other sites

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

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());

}

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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
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...