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.

Creating classes..

Featured Replies

Hi everyone, sorry for the noob question. But I'm simply trying to get other classes to work from the main class. I can't figure out what I'm doing wrong.. Once the code runs it thows an error when trying to send a log in the Tester class.

 

Main:

	public Tester g = new Tester();
	public String stateT;

	@Override
	public void onStart() {
		log("test1");
	}

	private enum State {
		TEST, WAIT
	};

	private State getState() {
		if (1 == 1)
			return State.TEST;
		return State.WAIT;
	}

	@Override
	public int onLoop() throws InterruptedException {
		switch (getState()) {
		case TEST:
			log("test2");
			g.logTest();
		case WAIT:
			break;
		}
		return random(200, 300);
	}

	@Override
	public void onExit() {
		log("");
	}

	@Override
	public void onPaint(Graphics2D g) {
	}
}

 

Tester Class:

public class Tester {
	private MethodProvider ggg;

	public Tester(MethodProvider ggg) {
	          this.ggg = ggg;
	     }

	public Tester() {
	}
  
	public void logTest() {
		ggg.log("test222222222222");
		NPC rGuide = ggg.npcs.closest("RuneScape Guide");
		ggg.log(rGuide);
	}
}

 

Thanks in advance for any help!

Edited by Mushphang

@Mushphang you are not passing the MethodProvider parameter to your Tester class, you are calling the empty constructor. This means that when you call logTest, a NullPointerException will be thrown as the ggg variable is null.

You should initialize your Tester instance in onStart instead, and pass a reference to a MethodProvider instance. As your main class extends MethodProvider, you can pass "this" as the parameter.

Edited by Explv

  • Author
15 minutes ago, Explv said:

You should initialize your Tester instance in onStart instead, and pass a reference to MethodProvider.

so something like this?

 

	public void onStart() {
		log("test1");
		Tester g = new Tester(this);
	}

edit: oh didn't see your edit, but that did it! much appreciated!

I declared the public Tester Test = new Tester(this); at a global level versus on start, not sure if that's an issue there at all.

 

Edited by Mushphang

9 minutes ago, Mushphang said:

so something like this?

 


	public void onStart() {
		log("test1");
		Tester g = new Tester(this);
	}

 

Well you will still need to store the variable globally, otherwise you won't be able to access it outside of the onStart method.

Declare the variable globally, but initialise it in onStart.

7 minutes ago, Mushphang said:

so something like this?

 


	public void onStart() {
		log("test1");
		Tester g = new Tester(this);
	}

 

Tester.java:

public class Tester {

  private final Script script;

  public Tester(Script script) {
      this.script = script;
  }

  public void Print(String message) {
      script.log(message);
  }

}

Your script main

public void onStart() {
  Tester tester = new Tester(this)
  tester.print("hello");
}

Wrote it in the reply box so sorry if there are any typos or if I missed anything. Hopefully that cleared things up a bit!

-Apa

  • Author
3 minutes ago, Explv said:

Well you will still need to store the variable globally, otherwise you won't be able to access it outside of the onStart method.

Declare the variable globally, but initialise it in onStart.

That did it!

 

Thank you so much for your help, you have no idea how much confusion you cleared up.

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.