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.

ConditionalSleep class

Featured Replies

A quick example of a ConditionalSleep class.
The API one is great and I suggest you use that one, this is more for learning purposes.

package org.bjornkrols.conditional;

import org.bjornkrols.imported.MilliTimer;

/**
 * @author 		Bjorn Krols (Botre)
 * @version		0.1
 * @since		March 16, 2015
 */

public abstract class ConditionalSleep {
	
	/**
	 * The time in milliseconds to sleep for per loop.
	 */
	private final int sleep;
	
	/**
	 * The maximum (exclusive) time of sleep, in milliseconds, after which the sleep loop will be broken.
	 */
	private final int timeout;
	
	/**
	 * @param sleep		The time in milliseconds to sleep for per loop.
	 * @param timeout	The maximum (exclusive) time of sleep in milliseconds after which the sleep loop will be broken.
	 */
	public ConditionalSleep(final int sleep, final int timeout) {
		this.sleep = sleep;
		this.timeout = timeout;
	}
	
	/**
	 * @return Whether to continue to sleep.
	 */
	public abstract boolean condition();
	
	/**
	 * Sleeps until the condition returns false or the timeout is reached.
	 */
	public void sleep() {
		MilliTimer timer = new MilliTimer();
		while (condition() && timer.getElapsedMilliSeconds() < timeout) {
			try {
				Thread.sleep(sleep);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
}

Implementation example:

// Wait while moving or making fire.
			new ConditionalSleep(300, 5000) {
				@Override
				public boolean condition() {
					return script.myPlayer().isMoving() || script.myPlayer().getAnimation() == FIREMAKING_ANIMATION;
				}
			}.sleep();

Edited by Botre

I really don't know why I havent been using conditional sleeps all this time.

  • 2 weeks later...

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.