Jack Posted June 4, 2014 Share Posted June 4, 2014 (edited) import java.awt.*; import javax.imageio.ImageIO; import org.osbot.rs07.api.ui.Message; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.io.IOException; import java.net.URL; @ScriptManifest(author = "Jack", name = "", version = 0.1, info = "", logo = "") public class Core extends Script { long startTime = 0; private final Image paintImage = getImage(""); int mouseX,mouseY; BasicStroke mouseStroke = new BasicStroke(1); public void onStart() { startTime = System.currentTimeMillis(); getBot().setHumanInputEnabled(false); } public int onLoop()throws InterruptedException{ return random(300, 400); } public void onPaint(Graphics2D g){ g.setStroke(mouseStroke); g.setColor(Color.WHITE); mouseX = mouse.getPosition().x; mouseY = mouse.getPosition().y; g.drawLine(mouseX-6, mouseY-6, mouseX+6, mouseY+6); g.drawLine(mouseX-6, mouseY+6, mouseX+6, mouseY-6); } public void onMessage(Message message) { if(message!=null){ } } private Image getImage(String url) { try { return ImageIO.read(new URL(url)); } catch(IOException e) { return null; } } public void onExit() { } } Edited June 4, 2014 by Divinity 2 Link to comment Share on other sites More sharing options...
Swizzbeat Posted June 4, 2014 Share Posted June 4, 2014 Why throw onLoop in a try/catch block if all you're doing is printing an exception is thrown (no help for debugging what so ever) Create BasicStroke as class variable so there aren't 40+ of them being created every second and killing the GC Create an int variable to hold mouse x/y coords so you're not retrieving 8 of the same Point object (same reason as above) 1 Link to comment Share on other sites More sharing options...
Jack Posted June 4, 2014 Author Share Posted June 4, 2014 Why throw onLoop in a try/catch block if all you're doing is printing an exception is thrown (no help for debugging what so ever) Create BasicStroke as class variable so there aren't 40+ of them being created every second and killing the GC Create an int variable to hold mouse x/y coords so you're not retrieving 8 of the same Point object (same reason as above) 1. the scripter would put whatever that want here? 2/3. adding it now Link to comment Share on other sites More sharing options...
Swizzbeat Posted June 4, 2014 Share Posted June 4, 2014 1. the scripter would put whatever that want here? 2/3. adding it now The exception thrown will be logged to the console output anyway, so it seems pretty redundant to add a try/catch block :p Link to comment Share on other sites More sharing options...
Extreme Scripts Posted June 4, 2014 Share Posted June 4, 2014 1. the scripter would put whatever that want here? 2/3. adding it now Updated your post with what he meant. Now you look normal ^_^ Link to comment Share on other sites More sharing options...
Swizzbeat Posted June 4, 2014 Share Posted June 4, 2014 (edited) Updated your post with what he meant. Now you look normal At least add the rest of the access modifiers if you added one of them Also, in my opinion instantiating variables looks better if done from within the constructor instead of right up top. That's opinionated though :p Edited June 4, 2014 by Swizzbeat Link to comment Share on other sites More sharing options...
PolishCivil Posted June 4, 2014 Share Posted June 4, 2014 Why throw onLoop in a try/catch block if all you're doing is printing an exception is thrown (no help for debugging what so ever) Create BasicStroke as class variable so there aren't 40+ of them being created every second and killing the GC Create an int variable to hold mouse x/y coords so you're not retrieving 8 of the same Point object (same reason as above) About 2 and 3 point. Actually java JVM is very optimized for huge amount of short lived objects, for such small ones this is psh, no matter. You can make tests if you dont belive. Thing changes if you code in c++/c 2 Link to comment Share on other sites More sharing options...
Swizzbeat Posted June 4, 2014 Share Posted June 4, 2014 (edited) About 2 and 3 point. Actually java JVM is very optimized for huge amount of short lived objects, for such small ones this is psh, no matter. You can make tests if you dont belive. Thing changes if you code in c++/c Just so I'm clear for what happens on the stack as well, does anything pushed onto the stack from a method immediately get popped off once those variables go out of scope (ie. exiting a method)? So in that case, it wouldn't matter how many primitive data types you create in a method since they will be popped off and not there lingering in the heap. Edited June 4, 2014 by Swizzbeat Link to comment Share on other sites More sharing options...
PolishCivil Posted June 4, 2014 Share Posted June 4, 2014 (edited) Just so I'm clear for what happens on the stack as well, does anything pushed onto the stack from a method immediately get popped off once those variables go out of scope (ie. exiting a method)? So in that case, it wouldn't matter how many primitive data types you create in a method since they will be popped off and not there lingering in the heap. They will be removed shortly, cuz you remove reference of your object each time you invoke method. While developing java you shouldn't take care of such things because u have jvm developed a way that will help you free unused references. Actualy in some (if not most) cases java memory allocation is even faster than c++ because java jvm doesn't have sheduled deallocation, it frees when it wants, when it needs to. In short answer: His methodInvoke -> create objects on stack -> no more use -> end of their life -> free. Yours LocalVar -> create object on heap -> use use use -> end of use on end of program -> free Difference? None for scripter/overall programmer/ Ofc we are talking about damn few data bytes lol. Don't you guys have more serious problems ;o Btw this skeleton, try to write api, this is kinda not herpfull ;P When i mean api, add some utilities show uses of methods etc, skeleton isn't much different than v1 Edited June 4, 2014 by PolishCivil 1 Link to comment Share on other sites More sharing options...
Jack Posted June 4, 2014 Author Share Posted June 4, 2014 They will be removed shortly, cuz you remove reference of your object each time you invoke method. While developing java you shouldn't take care of such things because u have jvm developed a way that will help you free unused references. Actualy in some (if not most) cases java memory allocation is even faster than c++ because java jvm doesn't have sheduled deallocation, it frees when it wants, when it needs to. In short answer: His methodInvoke -> create objects on stack -> no more use -> end of their life -> free. Yours LocalVar -> create object on heap -> use use use -> end of use on end of program -> free Difference? None for scripter/overall programmer/ Ofc we are talking about damn few data bytes lol. Don't you guys have more serious problems ;o Btw this skeleton, try to write api, this is kinda not herpfull ;P When i mean api, add some utilities show uses of methods etc, skeleton isn't much different than v1 I just wanted to see if anyone caught anything I missed for osbot 2. I should be updating when I can add more methods. Link to comment Share on other sites More sharing options...
Dreamliner Posted June 4, 2014 Share Posted June 4, 2014 They will be removed shortly, cuz you remove reference of your object each time you invoke method. While developing java you shouldn't take care of such things because u have jvm developed a way that will help you free unused references. Actualy in some (if not most) cases java memory allocation is even faster than c++ because java jvm doesn't have sheduled deallocation, it frees when it wants, when it needs to. In short answer: His methodInvoke -> create objects on stack -> no more use -> end of their life -> free. Yours LocalVar -> create object on heap -> use use use -> end of use on end of program -> free Difference? None for scripter/overall programmer/ Ofc we are talking about damn few data bytes lol. Don't you guys have more serious problems ;o Btw this skeleton, try to write api, this is kinda not herpfull ;P When i mean api, add some utilities show uses of methods etc, skeleton isn't much different than v1 Stop being such a stack trace 3 Link to comment Share on other sites More sharing options...
PolishCivil Posted June 4, 2014 Share Posted June 4, 2014 Stop being such a stack trace OSBot one, obfuscated, not helping at all ;( Link to comment Share on other sites More sharing options...
Dreamliner Posted June 4, 2014 Share Posted June 4, 2014 OSBot one, obfuscated, not helping at all ;( wats a osbot Link to comment Share on other sites More sharing options...
PolishCivil Posted June 4, 2014 Share Posted June 4, 2014 wats a osbot Obviously Something Being Obscure Today 3 Link to comment Share on other sites More sharing options...