Jump to content

How do slots work?


Solzhenitsyn

Recommended Posts

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

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
  • Like 1
Link to comment
Share on other sites

 

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

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

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

The API docs are very useful when scripting. 

 

http://osbot.org/api/org/osbot/rs07/api/util/ItemContainer.html

 

public int getSlot(Item item)
Gets the slot for the specified item.
Note: The item is matched based on id and amount only.
 
Parameters:
item - The item to match.
Returns:
The slot of the item. If no item is found, -1 is returned.

 

 

 

  • Like 2
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.
Note: Your post will require moderator approval before it will be visible.

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