Jump to content

Calling onPaint()?


Recommended Posts

Posted (edited)

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
Posted (edited)

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
Posted (edited)

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

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