Jump to content

Can't wrap my head around conditional sleep


Recommended Posts

Posted

Kind of based on this old thread I found 

 

When you have a conditional sleep statement:

new ConditionalSleep(10000) {
			public boolean condition() {
				return !tree.exists() || myPlayer().isAnimating();
				}
					}.sleep();

 

The osbot API states that the bot will sleep until the condition is false or the timeout expires. I get that you want the bot to sleep until the tree no longer exists since it will be cutting it in the meantime but I don't really understand why you must say myPlayer().isAnimating() and not !myPlayer().isAnimating(). Why would you want the bot to stop sleeping once the player starts animating (i.e. chopping the tree)? If someone could explain in pseudo code that would be great

Just starting scripting today so please be kind :)

Many thanks

Posted (edited)
4 minutes ago, liverare said:

return !tree.exists() || myPlayer().isAnimating();

"tree doesn't exist OR we are not animating"

Keyword: "OR"

If the tree exists, then we check whether we're chopping it. If we're not chopping it, aka. "animating", then we should probably 'wake up' and get back to chopping it.

That's what I don't get though, we have the ! operator in front of the first condition to state that the tree doesn't exist, why don't we have it in front of the isAnimating() condition? Like you said tree DOESN'T exist or we are NOT animating, so they're both false but only one of them uses the ! operator

Am I missing something obvious.. 

Don't you want to end the sleep if !tree.exists() || myPlayer().isNOTAnimating() i.e. !myPlayer().isAnimating()

Edited by Tommm39
Posted
1 hour ago, Taylorr said:

I see your confusion with using the ! Operator once or twice for the statement. I had the same question before I saw you even asked lol. Following this thread for the answer.

I'm sure I'm missing something obvious but I think it's weird that you're sleeping until the tree doesn't exist or your character isn't animating but you only use the ! for the former

Posted

With a conditional sleep, it sleeps until the condition is true, not false, or until the timeout expires.

What your condition is solely relies on the rest of your code. In this case we are sleeping until myPlayer().isAnimating() because presumably the script won't try to cut another tree when the player is animating.

Posted
3 minutes ago, d0zza said:

With a conditional sleep, it sleeps until the condition is true, not false, or until the timeout expires.

What your condition is solely relies on the rest of your code. In this case we are sleeping until myPlayer().isAnimating() because presumably the script won't try to cut another tree when the player is animating.

How often is the condition checked to see if it's true? 

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