Jump to content

Different class


Recommended Posts

Posted (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 by sirskitzo
Posted
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?

Posted

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.

  • Like 1
Posted
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.

  • Like 1

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