trekarcher 0 Share Posted May 5, 2020 Hi I am new to coding in Java and I am using OSRS to teach myself to code. This is probably a very stupid question / easy to answer but I have so far not been able to find a solution but I think the soloution is an array but maybe it isn't anyway please help I really appreciate it. As part of my script I want to deposit everything in the bank apart from a fly fishing rod and feathers. The work around I have for this is as follows getBank().depositAllExcept(309,314); For my other scripts I use a variable e.g getBank().depositAllExcept(PICKAXE); which is linked to public static final int PICKAXE = 1271; Because their are two items I cant make a variable for 309, 314. I was wondering if someone could help me with the correct code so that I can have something like getBank().depositAllExcept(FishEquipment); FishEquipment = 309,314 Link to comment Share on other sites More sharing options...
m4rr3co 67 Share Posted May 5, 2020 you can use lambda expression for that, idk if it's the most efficient, but it works quite well for me: while(getBank().deposit(item -> item != null && !item.getName().contains(" rod") && item.getName().equals("Feather"))); something like this Link to comment Share on other sites More sharing options...
Pseudo 179 Share Posted May 5, 2020 1 hour ago, m4rr3co said: you can use lambda expression for that, idk if it's the most efficient, but it works quite well for me: while(getBank().deposit(item -> item != null && !item.getName().contains(" rod") && item.getName().equals("Feather"))); something like this Generally using a while loop is bad practice, and I wouldn't recommend it here. In terms of depositing you could simply define an array of items you wish to bank and iterate through them depositing those that exist. Something like this should suffice: For (Item item : inventoryItems) { For (string itemName : item List) { If (item! = null and item.getName().equals(itemName)) { //do actions } } } Excuse the formatting/Pseudo code, written in the chat box just to try and give you an idea. Link to comment Share on other sites More sharing options...
m4rr3co 67 Share Posted May 5, 2020 30 minutes ago, Pseudo said: Generally using a while loop is bad practice, and I wouldn't recommend it here. In terms of depositing you could simply define an array of items you wish to bank and iterate through them depositing those that exist. Something like this should suffice: For (Item item : inventoryItems) { For (string itemName : item List) { If (item! = null and item.getName().equals(itemName)) { //do actions } } } Excuse the formatting/Pseudo code, written in the chat box just to try and give you an idea. yea, the use of "while" isn't the best... i agree Link to comment Share on other sites More sharing options...
m4rr3co 67 Share Posted May 5, 2020 36 minutes ago, Pseudo said: Generally using a while loop is bad practice, and I wouldn't recommend it here. In terms of depositing you could simply define an array of items you wish to bank and iterate through them depositing those that exist. Something like this should suffice: For (Item item : inventoryItems) { For (string itemName : item List) { If (item! = null and item.getName().equals(itemName)) { //do actions } } } Excuse the formatting/Pseudo code, written in the chat box just to try and give you an idea. sorry for multiple replies, but i can't edit my last post... the problem with your solution is that it doesn't solve the general situation of a random item inside the inventory... with this in mind, inside of an onLoop method, we could do: if(getInventory().contains(item -> item != null && !item.getName().equals("Feather") && !item.getName().contains(" rod"))) { getBank().depositAllExcept(item -> item != null && !item.getName().equals("Feather") && !item.getName().contains(" rod")); } still, i haven't tested this, but it would deposit everything except what OP wants to keep... what about this one? Link to comment Share on other sites More sharing options...
Pseudo 179 Share Posted May 5, 2020 1 hour ago, m4rr3co said: sorry for multiple replies, but i can't edit my last post... the problem with your solution is that it doesn't solve the general situation of a random item inside the inventory... with this in mind, inside of an onLoop method, we could do: if(getInventory().contains(item -> item != null && !item.getName().equals("Feather") && !item.getName().contains(" rod"))) { getBank().depositAllExcept(item -> item != null && !item.getName().equals("Feather") && !item.getName().contains(" rod")); } still, i haven't tested this, but it would deposit everything except what OP wants to keep... what about this one? He can simply inverse the logic of what I posted to do what he's trying to achieve. Link to comment Share on other sites More sharing options...
m4rr3co 67 Share Posted May 5, 2020 19 minutes ago, Pseudo said: He can simply inverse the logic of what I posted to do what he's trying to achieve. yea, totally... but what you think about the last solution i sent? trying to learn here Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.