Jump to content

Can't wrap my head around conditional sleep


Tommm39

Recommended Posts

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

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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? 

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