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.

Putting conditionalsleep in a method

Featured Replies

so basically, i want to put conditionalsleep in a method, so that i dont have to paste all those lines of codes everytime

 

this is what i got. i know it doesn't work, but i was wondering if someone could explain why it doesn't work.

 

 

This works

new ConditionalSleep(7000)
{
    @Override
    public boolean condition() throws InterruptedException
    {
        return ctx.getInventory().getAmount("Plank") > amountOfPlankInInventory;
    }          
}.sleep();

This doesn't

public void condSleep(int timeout,boolean statement)
{
    new ConditionalSleep(timeout)
    {
        @Override
        public boolean condition() throws InterruptedException
        {
                return statement;
        }          
    }.sleep();
}
 
condSleep(7000,ctx.getInventory().getAmount("Plank") > amountOfPlankInInventory);

Using lambda would make your first method a lot cleaner.

 

For the second method you could change the boolean from the statement to Callable<Boolean>. The thing you are doing wrong is that currently the statement will never change. The value is assigned when the method is called and will never change.
Anyway more info here: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Callable.html

public void condSleep(int timeout,boolean statement)
{
    new ConditionalSleep(timeout)
    {
        @Override
        public boolean condition() throws InterruptedException
        {
                return statement;
        }          
    }.sleep();
}
 
condSleep(7000,ctx.getInventory().getAmount("Plank") > amountOfPlankInInventory);

The method receives a boolean 'statement', which is evaluated to either true or false at the time of the method call. It's not going to magically change during the execution of the conditional sleep. So either you sleep the full time, or not at all.

Edited by FrostBug

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.