Verify 0 Share Posted May 29, 2020 Here's the class using setStartTime public class FirstScript extends TaskScript { private Anti t; @Override public void onStart() { t = new Anti(this); t.setStartTime(); } } I want the script to set START_TIME as the current time when I start the script. I then try to use this variable in a method such as getStartTime in an other class like so: public class Anti { public long START_TIME; public Anti(ScriptTest script) { } public double getStartTime() { double time = START_TIME; MethodProvider.log("[" + time + "]"); return time; } public void setStartTime() { this.START_TIME = System.currentTimeMillis(); } } The problem I am encountering is that the log from getStartTime display 0.0 instead of the current time, so I know something failed somewhere, but I can't figure out where. Any pointers would be appreciated. Thanks Link to comment Share on other sites More sharing options...
Hashtag 8671 Share Posted May 29, 2020 You're not showing us the way and when you call Anti::getStartTime, you might be calling it before assigning START_TIME any value. The code below works, so perhaps you'll find it helpful. Also, the DreamBot API has a built in Timer you could also use. It has some cool methods in it. public class FirstScript extends TaskScript { private Anti t; @Override public void onStart() { t = new Anti(this); } @Override public void onExit() { log(String.format("Time at start: %d", t.START_TIME)); log(String.format("Time now: %d", System.currentTimeMillis())); log(String.format("Elapsed time: %d", t.getElapsedTime())); } } public class Anti { public final long START_TIME; public Anti(FirstScript script) { START_TIME = System.currentTimeMillis(); } public long getElapsedTime() { return System.currentTimeMillis() - START_TIME; } } Link to comment Share on other sites More sharing options...
NovaGTX 106 Share Posted May 30, 2020 Why not just create a Timer and log the elapsed time when finished? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.