johnosrs1337 0 Share Posted June 21, 2022 First time posting and also new to programming so I’ve been having the hardest time trying to get an array to work for banking items like int bankItem; Int[] itemArray = new int[] {303, 1337, 1327}; bankItem = itemArray[0]; Bank.openClosest(); sleep(600); if(Bank.isOpen()) { Bank.depositAllExcept(bankItem); sleep(600); Bank.close(); I typed this out on my iPhone so I apologize for anything wrong with it but if anyone knows how I can use an array to cycle between items for a bank depending on what job my bot is currently doing it would be a great help I’ve been trying to understand what I’m doing wrong so I can progress further in my scripting. Link to comment Share on other sites More sharing options...
420x69x420 72 Share Posted June 21, 2022 To discriminate the activities your bot is doing you should compare stuff, and depending on what you're doing you want to use the easiest / most consistent / least complicated method of categorizing your bot's behavior. You already did it by saying if(Bank.isOpen()) because then you know only the code inside that if() block will execute if the bank is open. If your script is one Main class then u want to declare that int bankItem; inside your Main class, then find out what your bot is doing by comparing like I said, and depending on what your bot is doing you can set one of these: bankItem = itemArray[0]; bankItem = itemArray[1]; bankItem = itemArray[2]; then after making sure u set that bankItem correctly in the right spot, u can start banking with a generic banking function using bankItem etc. another option to ur array handling situation but basically equivalent is giving english names to ur int variables: int axe = 232; int pickaxe = 1337; int jar = 6969; int bankItem = jar; and if u want to really have them in an array then I don't like arrays personally... I use Lists... List<Integer> bankItems = new ArrayList<Integer>(); bankItems.add(234); bankItems.add(1337); bankItems.add(6969); int bankItem = bankItems.get(0); one difference in arrays and lists is that you can initialize the Lists in the Main class itself but only add to it in the @Override onLoop() / onStart() methods whereas you can initialize arrays as populated in just the Main class itself. johnosrs1337 1 Link to comment Share on other sites More sharing options...
camelCase 236 Share Posted June 21, 2022 whats the goal here? Link to comment Share on other sites More sharing options...
johnosrs1337 0 Author Share Posted June 21, 2022 So I’ve been learning java by writing bots because I’m in the hospital and cannot move from an accident and that’s super common to see here and other bots sites is people teaching themselves so what ended up happening is the resources I’m using to learn taught me arrays but I didn’t reach array lists yet or they might not even be in the material at all lol so I wrote all this super complicated to me code to add and remove elements to an array in a banking class that handles job items from job classes being passed to a banking class that stores items and removes everything it needs and keeps what it needs but I kept running into issues where I couldn’t pass the integer variables from my array to The bank withdraw method so I’m gonna try out array lists because from what I just read they are resizable but do I need to make my array list only in the main loop or can I make it in my banking class and add/remove from other job classes? Link to comment Share on other sites More sharing options...
420x69x420 72 Share Posted June 21, 2022 anytime I want to give access to a variable in a class to any other class, I declare that variable as public static, that way the variable is pertaining to that specific class, and others can see it and use it/modify it or make a copy of it, but there is only one instance of that variable and it is in the class it's declared in Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now