sirskitzo Posted February 14, 2018 Posted February 14, 2018 (edited) I have 2 files, main file and another one that I would like imported. Main file code: import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(author = "SirSkitzo", info = "", logo = "", name = "FirstScript", version = 1) public class test extends Script { public void onStart() throws InterruptedException { another a = new another(); a.test(); } public int onLoop() throws InterruptedException { return 0; } } and on the another class import org.osbot.rs07.script.Script; public class another { protected Script script; public another init(Script script){ this.script = script; return this; } public void test() { script.log("A message"); } } It doesn't work and I keep getting errors from the client. What am I doing wrong and how can I fix this? Edited February 14, 2018 by sirskitzo
Explv Posted February 14, 2018 Posted February 14, 2018 2 minutes ago, sirskitzo said: I have 2 files, main file and another one that I would like imported. Main file code: import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(author = "SirSkitzo", info = "", logo = "", name = "FirstScript", version = 1) public class test extends Script { public void onStart() throws InterruptedException { another a = new another(); a.test(); } public int onLoop() throws InterruptedException { return 0; } } and on the another class import org.osbot.rs07.script.Script; public class another { protected Script script; public another init(Script script){ this.script = script; return this; } public void test() { script.log("A message"); } } It doesn't work and I keep getting errors from the client. What am I doing wrong and how can I fix this? You didn't call init?
sirskitzo Posted February 14, 2018 Author Posted February 14, 2018 I thought I already did by another a = new another(); If not how else? @Explv
Chris Posted February 14, 2018 Posted February 14, 2018 pass instance in the constructor of the class another a = new another (instance);
sirskitzo Posted February 14, 2018 Author Posted February 14, 2018 @Chris Sorry for being a noob but I get an error in code now while doing this. Could you please show me how?
Alek Posted February 14, 2018 Posted February 14, 2018 Looks like you are trying to create a task/node system. You should probably just work on your OOP before doing something like this. If you are not working on a task/node system, what are you actually trying to achieve? 1
Jammer Posted February 14, 2018 Posted February 14, 2018 You should probably read up on some OOP principles as Alek said but I'll post a solution. public another init(Script script){ this.script = script; return this; } Change this into a constructor by removing the return type "another". another a = new another(this); pass an instance of your class that extends Script. 1
Explv Posted February 14, 2018 Posted February 14, 2018 1 hour ago, Jammer said: You should probably read up on some OOP principles as Alek said but I'll post a solution. public another init(Script script){ this.script = script; return this; } Change this into a constructor by removing the return type "another". another a = new another(this); pass an instance of your class that extends Script. That's not how you define a constructor, the constructor should have the same name as the class. It's not: public init(Script script) { } It's: public another(Script script) { } @sirskitzo you should follow some Java tutorials until you understand the basics. 1
Jammer Posted February 15, 2018 Posted February 15, 2018 8 hours ago, Explv said: That's not how you define a constructor, the constructor should have the same name as the class. It's not: public init(Script script) { } It's: public another(Script script) { } right, forgot to say that.