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.

How exactly does ConditionalSleep/Sleep and onLoop work together?

Featured Replies

Hi all,

So I'm experiencing an issue where my ConditionalSleep isn't blocking the execution of onLoop.

For example this snippet below should sleep until my inventory only contains one kind of item.

log("OnLoop has been run again");
new ConditionalSleep(Integer.MAX_VALUE) {
    public boolean condition() throws InterruptedException {
        return inventory.onlyContains('something');
    }
}.sleep();

But the logger shows that onLoop is being repetitively called.

Am I misunderstanding how ConditionalSleep works here? If so what is the correct way of blocking my script from running.

 

onLoop is basically a while(true) loop. It's the core of the script. It runs repeatedly until the script is stopped. 

 

ConditionalSleep is used to sleep until an action happens. I know a lot of people use this class for conditional sleeps:

So to drop something, you may do:

	if(inventory.drop(itemId)) {
                Sleep.sleepUntil(() -> !inventory.contains(itemId), 2000);
                Thread.sleep(MethodProvider.random(100, 400));
            }

It really cleans it up.

Hmmm interesting is this directly in the onLoop() or are you calling it from somewhere?

Also I noticed that if the inventory is completely empty than inventory.onlyContains() method will return true.

Try this:

new ConditionalSleep(Integer.MAX_VALUE) {
    @Override
    public boolean condition() throws InterruptedException {
        return !getInventory().isEmpty() && getInventory().onlyContains("Something");
    }
}.sleep();

Edited by BravoTaco

A few things to note

  • Make sure you calling the ConditionalSleep within the main thread, if you didn't create a new thread you dont have to worry about this.
  • Don't conditional sleep for the max duration, thats how your script gets stuck in the future and never recovers
  • Make sure the condition isnt evaluating to true, you may think it behaves in a certain way but theres every possibility that it doesnt, and you will need to add extra conditions
  • Author
13 hours ago, BravoTaco said:

Hmmm interesting is this directly in the onLoop() or are you calling it from somewhere?

Also I noticed that if the inventory is completely empty than inventory.onlyContains() method will return true.

Try this:


new ConditionalSleep(Integer.MAX_VALUE) {
    @Override
    public boolean condition() throws InterruptedException {
        return !getInventory().isEmpty() && getInventory().onlyContains("Something");
    }
}.sleep();

Turns out this was the issue 😅, getInventory.onlyContains was returning True when my inventory was empty. Looks like I didn't look at it thoroughly enough since the api for it does say "This method does not require that all the specified items exist, it determines whether there are no other items in the container".

Thanks for the help guys!

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.