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.

How do slots work?

Featured Replies

getSlot

public int getSlot(Filter<Item>... filter)

Gets the slot for the first item matched after filtering the container.

Parameters: filter - The filter(s). Returns: The first slot matched.

http://osbot.org/api/org/osbot/rs07/api/util/ItemContainer.html#getItem-org.osbot.rs07.api.filter.Filter...-

 

1) Will the method return 0 if no item is found? 

2) What orientation? Is the upper left slot 1, upper right 4, lower left 24, lower right 28? 

Edited by FuckingAshole

Iirc the first slot would be at index 0, then it progresses through rows then columns, so 0-1-2-3 would be the uppermost four slots, in order. I may be wrong, though.

This is something you could have easily figured out yourself by doing a small amount of testing.

 

The definition of getSlot() looks like:

public int getSlot(final Item item) {
    if(item == null) {
        return -1;
    } else {
        Item[] items = getInventory().getItems(); // returns an array of size 28
        for(int i = 0; i < items.length; i++) {
            if(items[i] != null && items[i].equals(item)) {
                return i;
            }
        }
        return -1;
    }
}

As you can see, if the item is not found it returns -1. Otherwise it returns a value from 0 (inclusive) to 28 (exclusive). 0 is the top left slot, 27 is the bottom right slot. The index increments from left to right:

0 1 2 3
4 5 6 7
8 9 10 11
etc.

Edited by Explv

  • Author

 

This is something you could have easily figured out yourself by doing a small amount of testing.

 

The definition of getSlot() looks like:

public int getSlot(final Item item) {
    if(item == null) {
        return -1;
    } else {
        Item[] items = getInventory().getItems(); // returns an array of size 28
        for(int i = 0; i < items.length; i++) {
            if(items[i] != null && items[i].equals(item)) {
                return i;
            }
        }
        return -1;
    }
}

As you can see, if the item is not found it returns -1. Otherwise it returns a value from 0 (inclusive) to 28 (exclusive). 0 is the top left slot, 27 is the bottom right slot. The index increments from left to right:

0 1 2 3
4 5 6 7
8 9 10 11
etc.

 

 

How did you find the source for the function? I have a hard time understanding API, but now that I know that getItems returns an array of  the contents of each slot (I was under the impression it returned an array of only the items contained) I understand perfectly. Thanks for your post.

Edited by FuckingAshole

How did you find the source for the function? I have a hard time understanding API

 

The source code is heavily obfuscated, so I wouldn't bother trying to read it.

 

In terms of the getSlot() method, as the API does not specify anything else, it is safe to assume that it would return an index from 0 to the inventory size. Most methods that return some form of index would start at 0, and you know that the inventory has 28 slots. As a valid index would always be positive, -1 is typically used to indicate that a valid index could not be found, you will find this everywhere in programming. Regarding the ordering, you can't know for sure as it's not in the API, but most people would assume left to right in rows. 

 

If you don't know exactly how something works, just write a little test and you'll find out.

Edited by Explv

It's returning an int, not a data structure.

I didn't say any different, I merely answered your question young sir.

 It simply returns the first index of a slot which is found to match your filtering criteria.

 

getSlot is a pretty misleading method name tbh, when it's purpose is almost exactly the same as indexOf. A more meaningful name would be getFirstSlotIndexOf, since there's a filter for a parameter and only one value gets returned. #indexOf default return value is -1, because 0 is a valid array index. With the value being -1, the programmer can use logic to determine if a slot had actually been returned, before attempting to access said slot one.

 

The orientation of slots is, I'm guessing, however Jagex dictate it to be, since all the widgets are designed by them. Khaleesi mentioned the orientation of the inventory slots.

Edited by liverare

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.