Mocro Posted October 3, 2015 Share Posted October 3, 2015 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... Quote Link to comment Share on other sites More sharing options...
FrostBug Posted October 3, 2015 Share Posted October 3, 2015 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. Quote Link to comment Share on other sites More sharing options...
Mocro Posted October 3, 2015 Author Share Posted October 3, 2015 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? Quote Link to comment Share on other sites More sharing options...
FrostBug Posted October 3, 2015 Share Posted October 3, 2015 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. 1 Quote Link to comment Share on other sites More sharing options...
Mocro Posted October 3, 2015 Author Share Posted October 3, 2015 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{ Quote Link to comment Share on other sites More sharing options...
FrostBug Posted October 3, 2015 Share Posted October 3, 2015 awsome thanks works now public class Inventory extends MethodProvider{ That's going to give you a NullPointerException, though. You have to do an exchangeContext first (MethodProvider#exchangeContext). 1 Quote Link to comment Share on other sites More sharing options...
Mocro Posted October 3, 2015 Author Share Posted October 3, 2015 That's going to give you a NullPointerException, though. You have to do an exchangeContext first (MethodProvider#exchangeContext). where do i put it inside my class or main? Quote Link to comment Share on other sites More sharing options...
FrostBug Posted October 3, 2015 Share Posted October 3, 2015 where do i put it inside my class or main? Either. As long as you're calling exchangeContext on your Inventory instance Quote Link to comment Share on other sites More sharing options...
Woody Posted October 3, 2015 Share Posted October 3, 2015 http://osbot.org/forum/topic/73842-isolating-the-api-from-script/ Quote Link to comment Share on other sites More sharing options...
Mocro Posted October 3, 2015 Author Share Posted October 3, 2015 (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(); http://osbot.org/forum/topic/73842-isolating-the-api-from-script/ 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 October 3, 2015 by Mocro Quote Link to comment Share on other sites More sharing options...
Joseph Posted October 3, 2015 Share Posted October 3, 2015 (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 October 3, 2015 by Joseph Quote Link to comment Share on other sites More sharing options...
Woody Posted October 3, 2015 Share Posted October 3, 2015 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. Quote Link to comment Share on other sites More sharing options...
Mocro Posted October 3, 2015 Author Share Posted October 3, 2015 man im really stuck here im trying my best to understand it just wont work just getting nulled... and im trying to code in objectoriented and in classes ... if i put everything in main class it works fine.... but then its not objectoriented... Quote Link to comment Share on other sites More sharing options...
Chris Posted October 4, 2015 Share Posted October 4, 2015 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; } Quote Link to comment Share on other sites More sharing options...
Mocro Posted October 4, 2015 Author Share Posted October 4, 2015 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.... Quote Link to comment Share on other sites More sharing options...