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.

Enum Help?

Featured Replies

I think I need Enum help.. not sure.

 

You see, I am still somewhat new to scripting, and I do know most of what I need to know for the OSBot API, but I still do not know as much about Java.

 

I am trying to make "FOOD" equal more than one thing.. so I did this:

 

public enum FOOD {
   Trout, Salmon, Tuna, Lobster,
   Monkfish, Shark, Swordfish 
}

 

 

 
I am not entirely sure if that's even how to do it, but then I try to do this: 
 
Entity food = client.getInventory().getItemForName(FOOD);

 

The red part being an error. I would just like it if someone could point me in the right direction with this. Thank you very much :)

 

you can't use enums for item ids or names. use an int to make every thing easyer. 

private int state, FOOD_ID, AMOUNT_TO_WITHDRAW; 

do this on start

 @Override
    public void onStart() {
    	try{
			FOOD_ID = Integer.parseInt(JOptionPane.showInputDialog("Please enter your food id"));
	     } catch (Exception e){
	    	
	     }
    	try{
			AMOUNT_TO_WITHDRAW = Integer.parseInt(JOptionPane.showInputDialog("How many would you like to bring?"));
	     } catch (Exception e){
	    	
	     }
	
    }

Then you can do 

Item food = client.getInventory().getItemForId(FOOD_ID);

Edited by NxJr

This is one way to use enums :

public enum FOOD {
                Trout, Salmon
	}

in your loop :

FOOD f = getState();
handleState(f);

separate methods :

public FOOD getState() {
    if (inventory.contains(trout)) {
         return FOOD.Trout;
      }
    if (inventory.contains(salmon)) {
         return FOOD.Salmon;
      }
}
public void handleState(FOOD state) {
		switch (state) {
		case Trout:
			do something
			break;
		case Salmon:
			do something
			break;
	}

Edited by Skype

Entity food = client.getInventory().getItemForName(FOOD.Shark.toString());

Will work out, if you wish to keep your current form, but you shouldn't! Your conventions are whack, and if the specific food item has a space in it's name, you're going to run into a little trouble. I'm in a bit of a rush, but I'll leave this here:

// enumeration declaration

public enum Food {
        
    SHARK(1234);
        
    private final int id;
        
    Food(final int id) {
        this.id = id;
    }
        
    public int getId() {
        return id;
    }
}

// usage
// NOTE - IT MAY NOT BE 'getItemForId', I wouldn't know - I haven't looked at OSBOT since the first/second release
Entity food = client.getInventory().getItemForId(Food.SHARK.getId());

Enums are great, what y'all talking about?

public enum Food {

    TROUT(333, "Trout"), SALMON, TUNA, LOBSTER, MONKFISH, SHARK, SWORDFISH;

    private int id;
    private String name;

    private Food(final int id, final String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

}

Enums are great for storing data + makes your code more clean and organised.

 

Example on how to access the data:

selectInventoryOption(client.getInventory().getSlotForName(Food.TROUT.getName()), "Eat");

/thread

>doesn't follow java naming conventions

fuck dat shit. When I learned java, the person that taught me used penis and boobs for like all the names. This helped differentiating naming and an actual predefined character such as;

public int fucks;

vs

public int value;

I would know that fucks was something you name yourself and value could seem like something that has to be used only when using something called "value" and I don't mean a variable. I mean like int. That is an int. It's not a name I made up. It helped me so yeah.

 

 

/thread

>doesn't follow java naming conventions

 

fuck dat shit. When I learned java, the person that taught me used penis and boobs for like all the names. This helped differentiating naming and an actual predefined character such as;

public int fucks;

vs

public int value;

I would know that fucks was something you name yourself and value could seem like something that has to be used only when using something called "value" and I don't mean a variable. I mean like int. That is an int. It's not a name I made up. It helped me so yeah.

 

trollololololol enums are so basic, you could learn them without help from somebody else. >,<

trollololololol enums are so basic, you could learn them without help from somebody else. >,<

Very ironic that you say you can learn enumerations on your own when you posted that in a thread about someone asking for help with enumerations...not to mention the video from thenewboston.

I guess you consider yourself good scripter since you can figure out something this simple on your own. I wish you the best of luck with your Abyss script.

  • Author

trollololololol enums are so basic, you could learn them without help from somebody else. >,<

 

sad.png

Edited by Fusion

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.