Jump to content

stuck on getInventory.....


Recommended Posts

Posted
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.script.MethodProvider;


public class Inventory {
	
    // WARNING: Untested code
    
    /** Holds the amount of willows we have cut */
    private int willowsCut = 0;
    /** Holds the last inventory that was compared */
    private Item[] lastInv;
    
    /**
     * Simple getter
     * @return the number of willows cut
     */
    public int getWillowsCut() {
        return willowsCut;
    }
    
    /**
     * Compares your last inventory with the current inventory.
     */
    public void compareItems() {
        if (lastInv == null) {
            lastInv = getInventory().getItems();
            return; // It will be the same, no need to check
        }
        
        String item = "Willow logs";
        Item[] currInv = getInventory().getItems();
        for (int i = 0; i < 28; i++) {
            // Check for the same thing
            if ((currInv[i] == null && lastInv == null)
                    || currInv[i].getName().equals(lastInv[i].getName()))
                continue; // Its the same, continue
            
            if (currInv[i] != null) {
                // We have an item when we didn't
                if (currInv[i].getName().equals(item))
                    willowsCut++; // It was a willow log, ++
            } else {
                // We don't have an item when we did
                if (lastInv[i].getName().equals(item))
                    willowsCut--; // It was a willow log, --
            }
        }
        lastInv = currInv; // Update the inv
    }
    
    /**
     * Run this when the lastInv needs refreshing, aka after banking
     */
    public void resetItems() {
        lastInv = getInventory().getItems();
    }
}

cant find the getInventory() try to import nothing works.. suggestion of eclipse nothing...

Posted

getInventory is a method defined in MethodProvider. The Script class inherits from MethodProvider, and that's why you can use it from classes that extend Script.

This class does not have any definition of that method, so you cannot use it here.

 

To use it, you should have a reference to the Script instance.

Posted

getInventory is a method defined in MethodProvider. The Script class inherits from MethodProvider, and that's why you can use it from classes that extend Script.

This class does not have any definition of that method, so you cannot use it here.

 

To use it, you should have a reference to the Script instance.

is it possible to use it with myPlayer method?

Posted

is it possible to use it with myPlayer method?

 

myPlayer() is also defined in MethodProvider.

Since your Inventory class here does not extend anything, there are no methods beyond the ones you've defined in the class yourself.

 

You have to either pass a reference to your Script instance, and call the MethodProvider methods thru that; or create a new instance of whatever API classes you need, and exchange contexts with them.

 

  • Like 1
Posted

myPlayer() is also defined in MethodProvider.

Since your Inventory class here does not extend anything, there are no methods beyond the ones you've defined in the class yourself.

 

You have to either pass a reference to your Script instance, and call the MethodProvider methods thru that; or create a new instance of whatever API classes you need, and exchange contexts with them.

 

awsome thanks works now :)

public class Inventory extends MethodProvider{
Posted (edited)

Either. As long as you're calling exchangeContext on your Inventory instance

 

i have no clue how this works.... 

	  	Inv invent = new Inv();
	  	Inv.this.exchangeContext(bot);
	  	invent.compareItems();
	  	banked = invent.getWillowsCut();
    private MethodProvider api;

    public void onStart() {
        api = new Inv();
        api.exchangeContext(getBot());

    }

did it in my class still null class called Inv en main class called main
Edited by Mocro
Posted (edited)

Because its is a new class and it extends method provider I say you create a constructor and exchange context with it in there. And also have either the bot or script as an argument of the constructor.

In your inv class in the constructor just do

ExchangeContext (script.getBot ())

ExchangeContext (bot instance)

In your main class that extends scriot, you must initialize your inv class and pass the argument to it.

Edited by Joseph
Posted

 

i have no clue how this works.... 

	  	Inv invent = new Inv();
	  	Inv.this.exchangeContext(bot);
	  	invent.compareItems();
	  	banked = invent.getWillowsCut();
    private MethodProvider api;

    public void onStart() {
        api = new Inv();
        api.exchangeContext(getBot());

    }

did it in my class still null class called Inv en main class called main

 

Read the guide and do it step by step.

Posted
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.script.MethodProvider;


public class Inventory {
	
    // WARNING: Untested code
    
    /** Holds the amount of willows we have cut */
    private int willowsCut = 0;
    /** Holds the last inventory that was compared */
    private Item[] lastInv;
    
    /**
     * Simple getter
     * @return the number of willows cut
     */
    public int getWillowsCut() {
        return willowsCut;
    }
    
    /**
     * Compares your last inventory with the current inventory.
     */
    public void compareItems() {
        if (lastInv == null) {
            lastInv = getInventory().getItems();
            return; // It will be the same, no need to check
        }
        
        String item = "Willow logs";
        Item[] currInv = getInventory().getItems();
        for (int i = 0; i < 28; i++) {
            // Check for the same thing
            if ((currInv[i] == null && lastInv == null)
                    || currInv[i].getName().equals(lastInv[i].getName()))
                continue; // Its the same, continue
            
            if (currInv[i] != null) {
                // We have an item when we didn't
                if (currInv[i].getName().equals(item))
                    willowsCut++; // It was a willow log, ++
            } else {
                // We don't have an item when we did
                if (lastInv[i].getName().equals(item))
                    willowsCut--; // It was a willow log, --
            }
        }
        lastInv = currInv; // Update the inv
    }
    
    /**
     * Run this when the lastInv needs refreshing, aka after banking
     */
    public void resetItems() {
        lastInv = getInventory().getItems();
    }
}

cant find the getInventory() try to import nothing works.. suggestion of eclipse nothing...

 

 

try

inside your Inventory class

private Script scriptInstance;
    public Inventory(Script scriptInstance){
        this.scriptInstance = scriptInstance;
    }
Posted

 

try

inside your Inventory class

private Script scriptInstance;
    public Inventory(Script scriptInstance){
        this.scriptInstance = scriptInstance;
    }

Thank you il try that its so weird you cant like call methode from that class objects are working for me now but i want to make classes im using public voids now in main class....

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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