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.

If statement without boolean?

Featured Replies

I've seen people using if statements like: if(Enemy.interact("Attack"){sleep;}  instead of just interacting and then sleeping.

I understand that they achieve the same thing but I don't understand how I can use a non boolean value in an if statement or does it become a boolean after executing it?

When people do that it means the method returns a boolean based on success. You can use this success boolean to sleep ONLY if the action was successful - this means that instead of sleeping after a misclick, you'll just try again immediately like a human would.

  • Author
2 minutes ago, Night said:

When people do that it means the method returns a boolean based on success. You can use this success boolean to sleep ONLY if the action was successful - this means that instead of sleeping after a misclick, you'll just try again immediately like a human would.

I see, thanks man

Enemy.interact("Attack")

That returns a boolean.

If that boolean value is true, then the bot successfully interacted with the enemy.

If that boolean value is false, then the bot failed.

The sleep is inside that IF statement so that you only sleep if you were successful. Because otherwise, you're going to be needlessly delaying yourself.

  • 2 weeks later...

I recently attempted to uploaded a script, and was told that i needed to use conditional sleeps. is this what he was referencing? (because all my sleeps are wrapped in a condition as shown above) im just a little confused.

17 minutes ago, roguehippo said:

I recently attempted to uploaded a script, and was told that i needed to use conditional sleeps. is this what he was referencing? (because all my sleeps are wrapped in a condition as shown above) im just a little confused.

were you using sleepWhile or sleepUntil ? Those are conditional sleeps as far as I'm aware.

edit: actually that's from another api I think osbot uses conditionalSleep()

	new ConditionalSleep(5000) {
          @Override
          public boolean condition() throws InterruptedException {
            return myPlayer().isUnderAttack();
          }
	}.sleep();

 

Edited by Theorems

7 minutes ago, Theorems said:

where you using sleepWhile or sleepUntil ? Those are conditional sleeps as far as i'm aware.

edit: actually that's from another api I think osbot uses conditionalSleep()


	new ConditionalSleep(5000) {
          @Override
          public boolean condition() throws InterruptedException {
            return myPlayer().isUnderAttack();
          }
	}.sleep();

 

ahhh, i was not doing this. so this will sleep for 5000 millisecond if the player is under attack? may i ask what the .sleep() is doing in this example?

Just now, roguehippo said:

ahhh, i was not doing this. so this will sleep for 5000 millisecond if the player is under attack? may i ask what the .sleep() is doing in this example?

I believe that sleeps until the condition myPlayer.isUnderAttack() is true or the 5000 milliseconds has expired. Not actually sure about the .sleep() I copy pasted that example from the open afk splasher script, maybe take a look at that code.

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.