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.

Keeping track of a global variable

Featured Replies

I know in Java there is no such thing as a global variable but I am looking for something similar.

 

I am writing a script that does several things in 4 areas. I need a way to update a variable to say "section one is done, move on to section two" and then in my other classes be able to check the state of this variable. Can someone point me in a direction?

Make a Util class or something similar, either use a public variable there or use getters and setters for the variable and pass the instance of the Util object into all of your classes.

If I am understanding correctly, why not just use booleans?

Boolean hasBanked

Then once it has banked, set it true and move on to the next step?

24 minutes ago, Juggles said:

If I am understanding correctly, why not just use booleans?

Boolean hasBanked

Then once it has banked, set it true and move on to the next step?

That doesn't make sense..

1 minute ago, andrewboss said:

That doesn't make sense..

How does it not make sense? 

start all booleans false, once it completes one thing, that boolean is true and moves onto next step until that one is true and continues.

He has 4 steps he wants to accomplish so he can use 4 booleans and after each one is completed set it true 

Edited by Juggles

  • Author
29 minutes ago, Juggles said:

If I am understanding correctly, why not just use booleans?

Boolean hasBanked

Then once it has banked, set it true and move on to the next step?

That's exactly what I was looking for. You are awesome as always. I have often said that this farming thing would be a lot easier if I knew Java!

I always optimize my code to less use primitive variables when possible.

 

	
	public enum States {
		BANKED, WHATEVER
	}
	
	public static States state;
	
	private static void transitionState(States state) {
		Class.states = state;
	}
	
	public static States getCurrentState() {
		return Class.state;
	}

Something along these lines could also be used (quickly made it up obviously)

Edited by Vichy

global variables do exist lol.

Seems like you're doing everything inside of a single class. You just need to init the variable within the class and any object or method can access it.

1 hour ago, dreameo said:

global variables do exist lol.

Seems like you're doing everything inside of a single class. You just need to init the variable within the class and any object or method can access it.

just go static :doge:

1 hour ago, Chris said:

just go static :doge:

then you force methods to be static

loop would look like this since you couldn't use any of your static methods inside

onLoop(){

 Main.cut()

 Main.bank()

 ...

}

12 hours ago, dreameo said:

then you force methods to be static

loop would look like this since you couldn't use any of your static methods inside

onLoop(){

 Main.cut()

 Main.bank()

 ...

}

 

12 hours ago, Team Cape said:

'public' for global variables related to an instance of a class

'public static' for global variables related to no particular instance

 

 

54 minutes ago, Chris said:

 

 

 

15 hours ago, dreameo said:

global variables do exist lol.

 

13 hours ago, Team Cape said:

'public' for global variables related to an instance of a class

 

14 hours ago, Chris said:

just go static :doge:

 

15 hours ago, dreameo said:

Seems like you're doing everything inside of a single class. You just need to init the variable within the class and any object or method can access it.

 

13 hours ago, Team Cape said:

'public' for global variables related to an instance of a class

'public static' for global variables related to no particular instance

 

13 hours ago, dreameo said:

then you force methods to be static

loop would look like this since you couldn't use any of your static methods inside

onLoop(){

 Main.cut()

 Main.bank()

 ...

}

 

  • Author

Thanks for all the good advice. I am not very sophisticated as a coder so the Booleans will suit my needs for now.

 

Baby steps.

 

I do appreciate the replies though, this community is great.

14 hours ago, dreameo said:

then you force methods to be static

loop would look like this since you couldn't use any of your static methods inside

onLoop(){

 Main.cut()

 Main.bank()

 ...

}

You can reference static variables from non-static instances.

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.