I hate retyping the basic script layout every time I write a new script so I made this class. I figured it could also benefit new scripters if I released it on the forums. I'll explain the code in notes.
import java.awt.Graphics;
import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;
@ScriptManifest(author = "Cloudnine", info = "TemplateScript v0.1", name = "TemplateScript", version = 0.1)//How the script will show up when you go to start it
public class TemplateScript extends Script {
long startTime;
long runTime;
public void onStart() {//This code executes when the script is started
log("TemplateScript v0.1 by Cloudnine has initialized!");
startTime = System.currentTimeMillis();
}
public void onExit() {//This code executes when the script is stopped
log("Thank you for using TemplateScript v0.1 by Cloudnine!");
log("Ran for " + runTime / 1000 + " seconds.");
}
public void onPaint(Graphics g) {//This is to "paint", or display, content on the screen
runTime = System.currentTimeMillis() - startTime;
g.drawString("TemplateScript v0.1", 450, 345);//X: 450 (left and right), Y: 345 (up and down)
g.drawString("by Cloudnine", 450, 360);
g.drawString("Run Time: " + (runTime / 1000), 450, 385);
}
public int onLoop() throws InterruptedException {
/*
* Place Code Here
*/
return 100;//sleeps for 100ms, then restarts this loop
}
}
Even if you don't need the explanation, you can put this in Eclipse and do Ctrl+F, Replace TemplateScript with ScriptName, rather than retyping this over and over.
If you want to see the functions OSBot provide you with, visit the api. http://osbot.org/api
If you are new to java, and want to learn enough to begin scripting, you can try out the Oracle Java Tutorials. That's where I learned. (Look it up on Google, it's easy to find). Also, for the beginner programmers, download an IDE if you don't use one. That will help you script 10x more efficiently. It's practically impossible to program efficiently without an IDE. An IDE is a text editor made for programmers. Ex: Eclipse, Netbeans, etc.. I prefer Eclipse. Random Tip: If you use Eclipse, press Ctrl+Shift+F to automatically format your code neatly.