Jump to content

How to use ConditonalSleep


Swizzbeat

Recommended Posts

Since I think it's important scripters do this instead of adding static sleeps here's a basic guide on how to use them.

 

The ConditonalSleep interface takes a timeout parameter as well as a condition method that requires overriding. When the sleep() method is invoked on the instantiated anonymous implementation it will sleep until either the timeout argument is met or the condition returns true. The condition method will return true if the condition was met before the specified timeout or false if the timeout has passed.

 

For example the following code will sleep until either 5000 milliseconds has passed or the condition method returns true, then return the value.

return new ConditionalSleep(5000) {
	@Override
	public boolean condition() throws InterruptedException {
		return sI.myPlayer().isAnimating();
	}
}.sleep();
Edited by Swizzbeat
  • Like 1
Link to comment
Share on other sites

 

I use the Timer class and do this, which is the same thing I assume. xd

time.reset();
while(time.isRunning() && script.myPlayer().isAnimating()) {
    MethodProvider.sleep(50);
}

Not really needed since the API already provides this in many different ways:

 

d616578977ea1f4711cedadb5508bceb.png

Edited by Swizzbeat
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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