Jump to content

Calling onPaint()?


NewmansScripts

Recommended Posts

Hello.

 

I am making a on screen GUI (paint) for my script and currently have all my code in the onPaint() method. The issue is my counter (in onLoop) occurs in a while loop and so the paint does not get updated until the while loop ends. Is there a way to call onPaint() in the while loop? The Client.onPaint() says it is depreciated.

 

Thanks!

Edited by NewmansScripts
Link to comment
Share on other sites

I've never run into this problem but, shouldn't paint update it whether or not it is in the onLoop?

 

Yes, the onPaint runs independently from the onLoop. However, if some while loop is preventing the updating of a variable--which the onPaint is calling--then the variable won't change.

int count = 0;
	
	@Override
	public int onLoop() throws InterruptedException {
		
		count = 0;
		while (SOME_CONDITION_SOON_TO_END) {
			
			...
			
		}
		count++;
		
		return 100;
	}
	
	@Override
	public void onPaint(Graphics2D g) {
		
		g.drawString("Count: " + count, 25, 25);
		
	}

The counter is being updated AFTER the loop. The onPaint doesn't receive a new value until then.

Edited by liverare
Link to comment
Share on other sites

Sorry my mistake. The counter is being updated in onMessage() shown here:

public void onMessage(Message message) throws java.lang.InterruptedException {
		String txt = message.getMessage().toLowerCase();
		if (txt.contains("you hammer")) {
			barsDone++;
		}
	}

There is a while statement in my while loop that check for the animation which as print the message that I am looking for.


Fixed the issue. Did away with my while loop. Seems like that was causing the issue

Edited by NewmansScripts
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...