Jump to content

Different class


sirskitzo

Recommended Posts

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
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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