Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Question Change String in main task from leaftask

Joined
Mar 12, 2019
Messages
61
Ok so im stuck, cant for the life of me get this to work. I am trying to change a string in my main class(treebot) from a LeafTask. Its doing my head in.

I tried to change it directly by implimenting a comman in the Leaftask-

new Cru5tyBot().status = ("Doing stuff...");

Didnt work!

In my main class I created a method to change it internaly -

public class Cru5tyBot extends TreeBot implements EmbeddableUI {
public String status = "Starting...";

public void updateStatus(String newStatus) {
this.status = newStatus;
}
}

and calling that method in the Leasf Task -

new Cru5tyBot().updateStatus("Doing stuff....");

Still didnt work

Should be simple but its driving me nuts, cant work out what im doing wrong, someone please help...
 
#1 Fabric Cleaner
Joined
Mar 18, 2017
Messages
393
Ok so im stuck, cant for the life of me get this to work. I am trying to change a string in my main class(treebot) from a LeafTask. Its doing my head in.

I tried to change it directly by implimenting a comman in the Leaftask-

new Cru5tyBot().status = ("Doing stuff...");

Didnt work!

In my main class I created a method to change it internaly -

public class Cru5tyBot extends TreeBot implements EmbeddableUI {
public String status = "Starting...";

public void updateStatus(String newStatus) {
this.status = newStatus;
}
}

and calling that method in the Leasf Task -

new Cru5tyBot().updateStatus("Doing stuff....");

Still didnt work

Should be simple but its driving me nuts, cant work out what im doing wrong, someone please help...

If this string is in your main class you can access it by using the Environment.getbot() method as follows: ((MainClassName)Environment.getbot()).stringname= “new string”.

Also, make sure the string is public in your mainclass!

I believe the reason your current implementation isnt’t working is because you created a new instance of your mainclass, so changing variables in that new instance wont affect anything in the first instance.
 
Last edited:
Joined
Mar 12, 2019
Messages
61
If this string is in your main class you can access it by using the Environment.getbot() method as follows: ((MainClassName)Environment.getbot()).stringname= “new string”.

Also, make sure the string is public in your mainclass!

I believe the reason your current implementation isnt’t working is because you created a new instance of your mainclass, so changing variables in that new instance wont affect anything in the first instance.

Thanks Fabreze, I knew it was creating a new instance and was 99% sure that was the issue but that was the only command I could get it to complie with. Its always easy once you see the answer, thank you for your help...
 
Ok new problem.

I am trying to do the same (change a Boolean value in my main class) only this time from my controller class. Whenever I try to use the Enviroment.getbot() it throws an exception.

Any ideas how to change main class values from the controller?
 
#1 Fabric Cleaner
Joined
Mar 18, 2017
Messages
393
Thanks Fabreze, I knew it was creating a new instance and was 99% sure that was the issue but that was the only command I could get it to complie with. Its always easy once you see the answer, thank you for your help...
 
Ok new problem.

I am trying to do the same (change a Boolean value in my main class) only this time from my controller class. Whenever I try to use the Enviroment.getbot() it throws an exception.

Any ideas how to change main class values from the controller?

The controller isn’t on the bot thread so thats why it’s throwing the error. To get around this you can pass your main class imas an argument into your controller usong a constructor. In your controller add a variable which stores your mainclass, and a constructor:

Class mainclass;

public controller(Class mainclass){

This.mainclass= mainclass;

}

And then when load up your controller in your mainclass, pass “this” as its argument, loader.load(controller(this)) or howevr you load your controller in your main class.

This way, you can access any public variables in your main class through

mainclass.variable=whatever

in your controller.
 
Joined
Mar 12, 2019
Messages
61
The controller isn’t on the bot thread so thats why it’s throwing the error. To get around this you can pass your main class imas an argument into your controller usong a constructor. In your controller add a variable which stores your mainclass, and a constructor:

Class mainclass;

public controller(Class mainclass){

This.mainclass= mainclass;

}

And then when load up your controller in your mainclass, pass “this” as its argument, loader.load(controller(this)) or howevr you load your controller in your main class.

This way, you can access any public variables in your main class through

mainclass.variable=whatever

in your controller.

Thanks Mate you've been a massive help.

Im sorry but I havnt scripted in a few years. Started with SCAR back in the day and end up on Powerbot and RSbot. Quit when whats his face went to work for Jagex 5 or so years ago. So Im very very rusty.

I pretty much rewrote my whole bot to get it working. Now functioning pretty well. I am getting an exception thrown every time I start my bot,

javafx.fxml.LoadException:
unknown path
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2425)
at com.Cru5tyBots.bots.Cru5tyBot.UI.Cru5tyBotUI.<init>(Cru5tyBotInfoUI.java:103)
at com.Cru5tyBots.bots.Cru5tyBot.Cru5tyBotbotInterfaceProperty(Cru5tyBot.java:88)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException

Which has something to do with
loader.load(stream.get());

Can you explain exactly waht stream.get() is doing any any idea why it may be throwing an exception? It doesnt sem to make any differance to my bot if I delete it all togehter but every exmple script I have disected seems to call it so im wondering what it does.
 
#1 Fabric Cleaner
Joined
Mar 18, 2017
Messages
393
Thanks Mate you've been a massive help.

Im sorry but I havnt scripted in a few years. Started with SCAR back in the day and end up on Powerbot and RSbot. Quit when whats his face went to work for Jagex 5 or so years ago. So Im very very rusty.

I pretty much rewrote my whole bot to get it working. Now functioning pretty well. I am getting an exception thrown every time I start my bot,

javafx.fxml.LoadException:
unknown path
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2425)
at com.Cru5tyBots.bots.Cru5tyBot.UI.Cru5tyBotUI.<init>(Cru5tyBotInfoUI.java:103)
at com.Cru5tyBots.bots.Cru5tyBot.Cru5tyBotbotInterfaceProperty(Cru5tyBot.java:88)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException

Which has something to do with
loader.load(stream.get());

Can you explain exactly waht stream.get() is doing any any idea why it may be throwing an exception? It doesnt sem to make any differance to my bot if I delete it all togehter but every exmple script I have disected seems to call it so im wondering what it does.
Join the Runemate slack and ask this in #development, I struggle with stacktraces and bugfixing in javafx myself and am not really sure what stream.get() does as Ive never called that before, but someone on there will be able to help!
 
Joined
Mar 12, 2019
Messages
61
Thanks mate, will do.

It fixed itself somehow, I was editing my controller and I dont know what I done but its no longer throwing the exception. Would still like to know what it does...
 
Top