Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Can't wrap my head around conditional sleep

Featured Replies

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

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.

  • Author
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

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.

  • Author
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

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.

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? 

25 minutes ago, Antonio Kala said:

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

Every 25 milliseconds from memory, I'm pretty sure you can also modify this value by adding another argument to ConditionalSleep.

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.