Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Beginner Scripting Question.

Featured Replies

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.

 

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.

  • Author
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.

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.

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

  • Author
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

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.

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.