Jump to content

If statement without boolean?


Jammer

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
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
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

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