Salty as fuck Posted March 9, 2016 Share Posted March 9, 2016 Alright so, I looked at quite a few tutorials, read quite a few posts and i'm still a tad confused. I have a main class and then I have other classes. If I'm trying to use methods in my secondary class, it tends to null out, even though methods are available. Halp pls package AIO; public class wc extends AIORuneScape{ int abc = 5; public void Woodcutting() throws InterruptedException { sleep(500); if (npcs.closest("Banker") != null) { log("test"); } } } This is the secondary class. Quote Link to comment Share on other sites More sharing options...
Vilius Posted March 9, 2016 Share Posted March 9, 2016 And you said oop is useless ;) 3 Quote Link to comment Share on other sites More sharing options...
Salty as fuck Posted March 9, 2016 Author Share Posted March 9, 2016 I don't like it, but for the sake of managing an aio rs script, I may as well Quote Link to comment Share on other sites More sharing options...
Token Posted March 9, 2016 Share Posted March 9, 2016 In order to access OSBot fields and methods you must have a valid Script instance reference which must also be the instance you happen to be defining as your main class. I suggest you pass it as a parameter to the constructor of each class and store it in a non-static field. Then you can instantiate the class from your main class, passing the main class as a reference for your other classes to use in order to access OSBot methods and fields. 3 Quote Link to comment Share on other sites More sharing options...
Bitshift Posted March 9, 2016 Share Posted March 9, 2016 (edited) If you are getting a NPE it's either because the object returns null (non-existent or out of index range) or you aren't properly initializing the API for other classes. To elaborate on the post above: public class Secondary extends ScriptNode { private API api; public Second(API api) { this.api = api; } } Edited March 9, 2016 by Bitshift Quote Link to comment Share on other sites More sharing options...
Salty as fuck Posted March 9, 2016 Author Share Posted March 9, 2016 In order to access OSBot fields and methods you must have a valid Script instance reference which must also be the instance you happen to be defining as your main class. I suggest you pass it as a parameter to the constructor of each class and store it in a non-static field. Then you can instantiate the class from your main class, passing the main class as a reference for your other classes to use in order to access OSBot methods and fields. 1 Quote Link to comment Share on other sites More sharing options...
GoldenGates Posted March 9, 2016 Share Posted March 9, 2016 You're making an AIO RS without understanding/usage of OOP here? Quote Link to comment Share on other sites More sharing options...
Salty as fuck Posted March 9, 2016 Author Share Posted March 9, 2016 You're making an AIO RS without understanding/usage of OOP here? I understand OOP, I don't understand multiple classes. Quote Link to comment Share on other sites More sharing options...
Bitshift Posted March 9, 2016 Share Posted March 9, 2016 I understand OOP, I don't understand multiple classes. One of the pinnacles of OOP is polymorphism, which by definition, will result in multiple classes. Quote Link to comment Share on other sites More sharing options...
Salty as fuck Posted March 9, 2016 Author Share Posted March 9, 2016 One of the pinnacles of OOP is polymorphism, which by definition, will result in multiple classes. Well, it's a good thing I have this here thread for that there point you're making. And 'one of'. Saying I know about Java doesn't necessarily imply I can list every single function and know exactly what to do in every situation without outside assistance either. Quote Link to comment Share on other sites More sharing options...
GoldenGates Posted March 9, 2016 Share Posted March 9, 2016 I still don't fully understand what you're trying to do. Are you trying to access wc methods from AIORunescape? so wc w = new wc(); wc.woodcut(); ? That's what I see it as rn. Quote Link to comment Share on other sites More sharing options...
Salty as fuck Posted March 9, 2016 Author Share Posted March 9, 2016 I still don't fully understand what you're trying to do. Are you trying to access wc methods from AIORunescape? so wc w = new wc(); wc.woodcut(); ? That's what I see it as rn. trying to call the woodcutting class from main script once it's needed then use shit like players.myplayer and so forth in the woodcutting class itself Quote Link to comment Share on other sites More sharing options...
Token Posted March 9, 2016 Share Posted March 9, 2016 (edited) Let me elaborate the post I made earlier since I couldnt post code from my phone. Main.Java package somePackage; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(name = "AIO Runescape", author = "JohnnyDepp", version = 6.9, info = "Unicorns", logo = "") public class Main extends Script { Woodcutting wc; @Override public void onStart() { wc = new Woodcutting(this); } @Override public int onLoop() { wc.cutTree(); return 100; } } Woodcutting.Java package somePackage; public class Woodcutting { Main main; public Woodcutting(Main mainReference) { this.main = mainReference; } public void cutTree() { main.log("Time to cut some shit"); // insert actual code } } The above code should spam your logger with "Time to cut some shit". Edited March 9, 2016 by Token 1 Quote Link to comment Share on other sites More sharing options...
Salty as fuck Posted March 9, 2016 Author Share Posted March 9, 2016 Let me elaborate the post I made earlier since I couldnt post code from my phone. Main.Java package somePackage; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(name = "AIO Runescape", author = "JohnnyDepp", version = 6.9, info = "Unicorns", logo = "") public class Main extends Script { Woodcutting wc; @Override public void onStart() { wc = new Woodcutting(this); } @Override public int onLoop() { wc.cutTree(); return 100; } } Woodcutting.Java package somePackage; public class Woodcutting { Main main; public Woodcutting(Main mainReference) { this.main = mainReference; } public void cutTree() { main.log("Time to cut some shit"); // insert actual code } } The above code should spam your logger with "Time to cut some shit". thanks bae, this worked perfectly Quote Link to comment Share on other sites More sharing options...
nyan Posted March 9, 2016 Share Posted March 9, 2016 (edited) Let me elaborate the post I made earlier since I couldnt post code from my phone. Main.Java package somePackage; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(name = "AIO Runescape", author = "JohnnyDepp", version = 6.9, info = "Unicorns", logo = "") public class Main extends Script { Woodcutting wc; @Override public void onStart() { wc = new Woodcutting(this); } @Override public int onLoop() { wc.cutTree(); return 100; } } Woodcutting.Java package somePackage; public class Woodcutting { Main main; public Woodcutting(Main mainReference) { this.main = mainReference; } public void cutTree() { main.log("Time to cut some shit"); // insert actual code } } The above code should spam your logger with "Time to cut some shit". package trumpbitch; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import trumpbitch.Woodcutting; @ScriptManifest(name = "trumpscape", author = "trump", version = 6.9, info = "trump", logo = "trump") public class Main extends Script { @Override public void onStart() { // nothing cause trump } @Override public int onLoop() { Woodcutting.cutTree(this); return 100; } } package trumpbitch; import org.osbot.rs07.script.Script; public class Woodcutting { public static boolean cutTree(Script script) { script.log("trump for pres"); // insert just the tip return false; } } this way is pretty much the same thing but i find it's easier to copy paste to new scripts this way. good luck Edited March 9, 2016 by Shiny 1 Quote Link to comment Share on other sites More sharing options...