Jump to content

How to check ground for array items?


computor

Recommended Posts

I have an array that stores every string value a person puts into it.

 

public String[] temp;

temp = itemsToPickUp.getText().split("\n");

 

(itemsToPickUp is a text box in my GUI)

 

so if the user puts in:

 

Lobster

Bones

Coins

Fire runes

 

it is stored in the array as:

temp[0] = "Lobster";

temp[1] = "Bones";

temp[2] = "Coins";

temp[3] = "Fire runes";

 

and so on for however many items they decide to add into the text box.

 

My problem now is, how do I get the bot to pick the items up off the ground.

I've tried:

 

GroundItem loot = groundItems.closest(temp);
if (!myPlayer().isAnimating()) {
loot.interact("Take");
}

 

but for some reason it only picks up the LAST item in the array, and doesn't check for any other items. So in this instance it would pick up fire runes, and nothing else.

 

How do I get the bot to check for EVERY item in the array?

Edited by computor
Link to comment
Share on other sites

Try this: 

 

 

for (int i = 0; i < temp.length; i++){

   if (groundItems.closest(temp[i]) != null) {
            GroundItem loot = groundItems.closest(temp[i]);
            loot.interact("Take");

  }

}

       
Obviously you'll want some other stuff, like to check if your inventory is full, failsafes to make sure it does loot etc.          
Edited by Molly
Link to comment
Share on other sites

@Apaec, it still only takes the last item on the list.


Here's my GUI:

private void thisWindowClosed(WindowEvent e) { //use this handler to check to see if the window is closed or not.
			temp = itemsToPickUp.getText().split("\n"); //on closing, it sets the values in itemsToPickUP to the temp[] array (defined above) after every split (new line).
		}
private void initComponents() {

			itemsToPickUp = new JTextPane();

			//======== scrollPane1 ========
			{
				scrollPane1.setViewportView(itemsToPickUp);
			}
			contentPane.add(scrollPane1);
			scrollPane1.setBounds(25, 60, 215, 105);

and here is my array:

public String[] temp;

and my loop:

		for (String s : temp) {
			GroundItem item = this.groundItems.closest(s);
			if (item != null)
				if(item.interact("Take"))
					sleep(random(600,1000));
		}

Have I done something wrong?

 

I know all the variables are stored into the array that the user puts into the scroll box because I've painted them onscreen to test to see if they were being stored correctly. I just don't know why the loop is only searching for the last item on the list.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...