Apaec Posted August 3, 2017 Share Posted August 3, 2017 (edited) 6 hours ago, dreameo said: This comes from Oracles code convention. Not sure what you're saying at the end lol. Oracles naming conventions say that constants should be caps and underscores, but 'constant' is not synonymous with the final keyword. For example, the final keyword can be assigned to variables which may not have the same value between separate instances of a program. Consider the class below: public class Demo { private final String someString; public Demo(String string) { someString = string; } public String getString() { return someString; } } The class can be used as follows: System.out.println(new Demo("Hello").getString()); //> Hello System.out.println(new Demo("abcdefg").getString()); //> abcdefg You will notice that, although the variable 'someString' is final, its value is not the same in the example above (when two separate instances of the Demo class are created) and thus is not globally constant, hence a CAPS_AND_UNDERSCORES variable name is not appropriate. In the next example however, it would be: public class DemoTwo { private final String SOME_STRING = "I'm constant!"; public Demo() {} public String getString() { return SOME_STRING; } } Using it: System.out.println(new DemoTwo().getString()); //> "I'm constant!" I hope that makes sense and you now understand what I was previously trying to say and why I think that the final keyword does not always mean caps and underscores should be used for naming! Apa Edited August 3, 2017 by Apaec Quote Link to comment Share on other sites More sharing options...
dreameo Posted August 3, 2017 Share Posted August 3, 2017 Yea I agree Apa completly. But relative to the code by op, names of items are constant ;), regardless of how he sets up the code. I get what you mean however. Quote Link to comment Share on other sites More sharing options...
kingbutton Posted August 4, 2017 Author Share Posted August 4, 2017 On 8/2/2017 at 3:12 PM, Imateamcape said: no calls to methods inherited from Script are allowed before onLoop(). This means you can't call myPlayer() or npcs.closest() Okay, So I learned that myPlayer(), NPCS, and RS2Objects need to be in the method to be able to use them. But what If I have multiple methods that need to call them, do I just declare it multiple times? Cause I'm trying to make a inventory check method, ( btw I got the script to run ) . Where it checks if my inventory has a net or not, if it doesn't it goes bank and grabs one. But I also have a method where when my inventory is full it goes bank and such. So do I have to declare it twice cause that doesn't make sense to me. Quote Link to comment Share on other sites More sharing options...
dreameo Posted August 4, 2017 Share Posted August 4, 2017 (edited) public boolean hasItem(String itemName){ return getInventory.contains(itemName); } You just create methods to reduce any duplicate code. Example: I can call this method whenver i need to see if i have I have an item in my inventory. For more practical use, the methods you invoke will have larger pieces of code inside them. Edited August 4, 2017 by dreameo Quote Link to comment Share on other sites More sharing options...
Team Cape Posted August 4, 2017 Share Posted August 4, 2017 (edited) 2 hours ago, dreameo said: public boolean hasItem(String itemName){ return getInventory.contains(itemName); } You just create methods to reduce any duplicate code. Example: I can call this method whenver i need to see if i have I have an item in my inventory. For more practical use, the methods you invoke will have larger pieces of code inside them. The method is already created. Why would you remake it? Also, getInventory isn't a field, it's a method Edited August 4, 2017 by Imateamcape Quote Link to comment Share on other sites More sharing options...
dreameo Posted August 4, 2017 Share Posted August 4, 2017 2 hours ago, kingbutton said: Cause I'm trying to make a inventory check method, ( btw I got the script to run ) . Quote Link to comment Share on other sites More sharing options...
kingbutton Posted August 4, 2017 Author Share Posted August 4, 2017 Well to anybody interested! I figured out how to use methods, not sure if they're used efficiently though or if i can clean anything up, do more checks, iono. But I GOT IT WORKING AND THAT'S WHAT MATTERS, also decided to change it to a barb fisher. https://paste.ofcode.org/W8ezZaeTJckFcUx5MzYAVr If anybody has some constructive criticism, besides my really simple question. Toss em here! 1 Quote Link to comment Share on other sites More sharing options...