Jump to content
Etra

Beginner Scripting Question.

Recommended Posts

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.

Link to comment
Share on other sites

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 by Dot
expanding
Link to comment
Share on other sites

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 by Etra
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...