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.

ConditionalLoop class

Featured Replies

A quick example of a ConditionalLoop 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 26, 2015
 */

public abstract class ConditionalLoop extends Thread {

	/**
	 * This loop's timer (millisecond precision).
	 */
	private MilliTimer timer;
	
	/**
	 * The maximum (exclusive) time of looping, in milliseconds, after which the loop will be broken.
	 */
	private int timeout;
	
	public ConditionalLoop(final int timeout) {
		setDaemon(true);
		setTimeout(timeout);
	}
	
	/**
	 * A no-argument constructor with a default timeout of 10 seconds.
	 */
	public ConditionalLoop() {
		this(10000);
	}
	
	@Override
	public void run() {
		preLoop();
		while (condition()) {
			if (timer.getElapsedMilliSeconds() > timeout) {
				onTimeout();
				break;
			}
			try {
				Thread.sleep(onLoop());
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		postLoop();
	}
	
	/**
	 * @return Whether to continue to loop.
	 */
	public abstract boolean condition();
	
	/**
	 * Executes before the loop starts.
	 */
	public void preLoop() { 
		timer = new MilliTimer();
	};
	
	/**
	 * The actual loop.
	 * 
	 * @return The time to sleep for, in milliseconds, after each iteration.
	 */
	public abstract int onLoop();
	
	/**
	 * Executes after the loop.
	 */
	public void postLoop() { };
	
	/**
	 * Executes when the loop has timed out.
	 */
	public void onTimeout() { }
	
	/**
	 * Sets the timeout (in milliseconds).
	 *
	 * @param milliseconds The time out (in milliseconds).
	 */
	public void setTimeout(int milliseconds) {
		timeout = milliseconds;
	}
	
}

Edited by Botre

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.