computor Posted December 15, 2014 Share Posted December 15, 2014 (edited) 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 December 15, 2014 by computor Link to comment Share on other sites More sharing options...
computor Posted December 15, 2014 Author Share Posted December 15, 2014 Something like this??? (but this doesn't work) for (int i = 0; i < temp.length; i++){ GroundItem loot = groundItems.closest(temp[i]); loot.interact("Take"); } Link to comment Share on other sites More sharing options...
Molly Posted December 15, 2014 Share Posted December 15, 2014 (edited) 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 December 15, 2014 by Molly Link to comment Share on other sites More sharing options...
computor Posted December 15, 2014 Author Share Posted December 15, 2014 It still only picks up the last item in the list. Link to comment Share on other sites More sharing options...
Molly Posted December 15, 2014 Share Posted December 15, 2014 It still only picks up the last item in the list. Ahh ok, I reread the OP and it looks like the way you're reading in data only the very last string entered is put into temp. Link to comment Share on other sites More sharing options...
computor Posted December 15, 2014 Author Share Posted December 15, 2014 (edited) How does one change that? (i thought it was grabbing all data, so clearly i'm wrong) Here's my code: http://pastebin.com/h56xBi2t Edited December 15, 2014 by computor Link to comment Share on other sites More sharing options...
Molly Posted December 15, 2014 Share Posted December 15, 2014 Sorry I was wrong that does actually work, forgive me its 4 am and I am exhausted lol. I'm not exactly sure why you are having difficulty looting. I'll look over your code real quick and see if I can spot something. Link to comment Share on other sites More sharing options...
Extreme Scripts Posted December 15, 2014 Share Posted December 15, 2014 Try putting in a sleep after you interact with the item. As you have it its just looping continuously reaching the end of the list. Link to comment Share on other sites More sharing options...
Apaec Posted December 15, 2014 Share Posted December 15, 2014 (edited) Just use this: for (String s : temp) { GroundItem item = this.groundItems.closest(s); if (item != null) if(item.interact("Take")) sleep(random(600,1000)); } Edited December 15, 2014 by Apaec 1 Link to comment Share on other sites More sharing options...
computor Posted December 15, 2014 Author Share Posted December 15, 2014 @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 More sharing options...
computor Posted December 16, 2014 Author Share Posted December 16, 2014 Problem was solved by apaec. Link to comment Share on other sites More sharing options...