Etra Posted November 6, 2018 Share Posted November 6, 2018 I have a question about: NPC npc = getNpcs().closest("Cow"); How come we use NPC instead of NPCS? Isn't the getNpcs method in the NPCS class? Sorry if this is a stupid question, thanks. Quote Link to comment Share on other sites More sharing options...
Night Posted November 6, 2018 Share Posted November 6, 2018 NPC is the object type, getNpcs() returns the Npcs class which you use to find it. Think of it like this, you use the Npcs class to find it (cause there's more than one NPC), then store it as an NPC. Quote Link to comment Share on other sites More sharing options...
Etra Posted November 6, 2018 Author Share Posted November 6, 2018 1 minute ago, Night said: NPC is the object type, getNpcs() returns the Npcs class which you use to find it. Think of it like this, you use the Npcs class to find it (cause there's more than one NPC), then store it as an NPC. Think I got it. Will me learning more about classes help me understand this better? If not what can resource can I use? Thanks for the help. Quote Link to comment Share on other sites More sharing options...
Night Posted November 6, 2018 Share Posted November 6, 2018 Just now, Etra said: Think I got it. Will me learning more about classes help me understand this better? If not what can resource can I use? Thanks for the help. Definitely, do some research about the basic of Objects in Object Oriented Programming, Classes, Inheritance, and methods/variables. 1 Quote Link to comment Share on other sites More sharing options...
Dot Posted November 6, 2018 Share Posted November 6, 2018 (edited) I am not an OSBot guru by any means but I do have a lot of programming experience. We use NPC because it is (almost always) used to reference a single NPC. getNpcs() targets a group of them but the purpose of getClosest(value) is to narrow it down to a single NPC. It has very little to do with what class the method resides in because the naming of types has more to do with how they are actually used in the language. As you continue to learn it will become more and more clear how things are named and why. To elaborate, the NPC in `NPC chicken = getNpcs.closest("chicken")` is actually the type of variable. It's the same as String in `String myName = "Dot"` or int in `int myAge = 9001`. Technically, it can be anything the compiler accepts. `getNpcs().closest("Chicken").getLevel()` is actually an `int` (because it is the level of the closest chicken, as an integer), so it needs to be written as `int chickenLevel = getNpcs().closest("Chicken").getLevel()` and the NPC type has nothing to do with it. If you don't understand that now, you will soon. The NPC type is specific to OSBot's API but if you familiarize yourself will other variable types in Java you'll figure it out quickly. Edited November 6, 2018 by Dot expanding Quote Link to comment Share on other sites More sharing options...
Etra Posted November 6, 2018 Author Share Posted November 6, 2018 (edited) 11 hours ago, Dot said: I am not an OSBot guru by any means but I do have a lot of programming experience. We use NPC because it is (almost always) used to reference a single NPC. getNpcs() targets a group of them but the purpose of getClosest(value) is to narrow it down to a single NPC. It has very little to do with what class the method resides in because the naming of types has more to do with how they are actually used in the language. As you continue to learn it will become more and more clear how things are named and why. To elaborate, the NPC in `NPC chicken = getNpcs.closest("chicken")` is actually the type of variable. It's the same as String in `String myName = "Dot"` or int in `int myAge = 9001`. Technically, it can be anything the compiler accepts. `getNpcs().closest("Chicken").getLevel()` is actually an `int` (because it is the level of the closest chicken, as an integer), so it needs to be written as `int chickenLevel = getNpcs().closest("Chicken").getLevel()` and the NPC type has nothing to do with it. If you don't understand that now, you will soon. The NPC type is specific to OSBot's API but if you familiarize yourself will other variable types in Java you'll figure it out quickly. Thanks, I'm still learning but I'm starting to understand it better. Your example about String is good. I'm used to seeing variable types of int, double, string, and having an NPC type threw me off. As I understand it, we have to use the getNpcs method from the NPCS class because there are multiple npcs. We then store that in the NPC type variable? Edited November 6, 2018 by Etra Quote Link to comment Share on other sites More sharing options...
tinnetju Posted November 6, 2018 Share Posted November 6, 2018 21 minutes ago, Etra said: Thanks, I'm still learning but I'm starting to understand it better. Your example about String is good. I'm used to seeing variable types of int, double, string, and having an NPC type threw me off. As I understand it, we have to use the getNpcs method from the NPCS class because there are multiple npcs. We then store that in the NPC type variable? Yes, closest returns only 1 NPC thats why it can be stored in just an NPC object. If you want to store multiple NPC's you can use a List for example but you have to call a different method because closest will only return 1. Quote Link to comment Share on other sites More sharing options...