Jump to content

Calling an Instance in onLoop


Expels

Recommended Posts

If I were to use the following code in my onLoop it uses a lot of CPU, what would be a better option?

new ChopTrees(this);
Create it in onStart and store it globally.

I assume you have all your chopping code in the constructor, move it into a separate method and call that on the created object:

chopTreesObj.chop();

Edited by Explv
Link to comment
Share on other sites

Create it in onStart and store it globally.

I assume you have all your chopping code in the constructor, move it into a separate method and call that on the created object:

chopTreesObj.chop();

 

Okay, so I have this in a separate class (file) and in my onStart:

public class ChopTrees  {
	public void chopTrees(Script sI) {
public void onStart() {
		new ChopTrees();

What now?

Link to comment
Share on other sites

Okay, so I have this in a separate class (file) and in my onStart:

public class ChopTrees  {
	public void chopTrees(Script sI) {
public void onStart() {
		new ChopTrees();

What now?

 

I recommend you follow some Java tutorials before trying to write scripts:

 

https://www.tutorialspoint.com/java/java_object_classes.htm

Edited by Explv
  • Like 2
Link to comment
Share on other sites

Could do this, as this is what I do when I call methods from a different class

 

public class main extends Script {

Classname m = new classname();

 

onstart(){

 You can call it in the onstart class by doing this

m.(whatever method you are gonna use from the other class)

 

}

or you could call it on your onloop, or instead your switches.

 

}

Link to comment
Share on other sites

Learn how to code before you copy-pasta task node systems. Also why the hell are you passing script and not the Bot instance?

 

Edit2: I deleted that tutorial

 

Too many new scripters are using those node frameworks without understanding them. There is nothing wrong with using the simple loop until you understand OOP.

 

Once you learn more about Java, you will be able to write and understand that node system. For now, just stick with learning step by step. 

  • Like 2
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...