Joseph Posted November 7, 2014 Share Posted November 7, 2014 Typically in most tutorial or snippet with in OSB. You have many of them telling you to create a script instance with in a new class. So that your allowed to use methods within the Script instance. Now i found a better and easier way of doing this. So here an example class public class WorldHopper { private Script script; public final static int[] P2P_WORLDS = {301, 302, 303, 304, 305, 306, 309, 310, 311, 312, 313, 314, 317, 318, 319, 320, 321, 322, 326, 327, 328, 329, 330, 333, 334, 335, 336, 338, 341, 342, 343, 344, 345, 346, 349, 350, 351, 352, 353, 354, 357, 358, 359, 360, 361, 362, 366, 367, 368, 369, 370, 373, 374, 375, 376, 377, 378}; public final static int[] F2P_WORLDS = {308, 316}; public final static int[] PVP_WORLDS = {325, 337}; public final static int[] TRIAL_WORLDS = {381, 382, 383, 384, 393, 394}; public WorldHopper(Script script) { this.script = script; } public void hopWorld(int...worlds) { List<Integer> worldList = new ArrayList<Integer>(); for (int world: worlds){ worldList.add(world); } if (script.interfaces.closeOpenInterface()) { int index = MethodProvider.random(worldList.size()); script.worldHopper.hop(worldList.get(index)); }else{ script.log("can't close open interface"); } } } See how within your class constructor you have Script argument that will initialize your private field Script. So whenever you want to use the bank. You'll have to use your script instance then call the bank method. Finally call the methods you want to use from the bank class. What you should do stead would be to extend Method Provider. Then within the constructor you will use the method within the Method Provider class to help you initialize all the classes it has. Example of the code above redone. public class WorldHopper extends MethodProvider{ public final static int[] P2P_WORLDS = {301, 302, 303, 304, 305, 306, 309, 310, 311, 312, 313, 314, 317, 318, 319, 320, 321, 322, 326, 327, 328, 329, 330, 333, 334, 335, 336, 338, 341, 342, 343, 344, 345, 346, 349, 350, 351, 352, 353, 354, 357, 358, 359, 360, 361, 362, 366, 367, 368, 369, 370, 373, 374, 375, 376, 377, 378}; public final static int[] F2P_WORLDS = {308, 316}; public final static int[] PVP_WORLDS = {325, 337}; public final static int[] TRIAL_WORLDS = {381, 382, 383, 384, 393, 394}; public WorldHopper(Script script) { exchangeContext(script.bot); } public void hopWorld(int...worlds) { List<Integer> worldList = new ArrayList<Integer>(); for (int world: worlds){ worldList.add(world); } if (interfaces.closeOpenInterface()) { int index = MethodProvider.random(worldList.size()); worldHopper.hop(worldList.get(index)); }else{ log("can't close open interface"); } } } Link to comment Share on other sites More sharing options...
Eliot Posted November 7, 2014 Share Posted November 7, 2014 I'm not seeing why this is better. It prevents you from extending something more important, even if you don't have anything else to extend, is this just to avoid typing script? Link to comment Share on other sites More sharing options...
Swizzbeat Posted November 7, 2014 Share Posted November 7, 2014 Umm wouldn't this create a ton of unnecessary MethodProvider class instances? Passing it via constructor just passes the reference, keeping the heap clean. 2 Link to comment Share on other sites More sharing options...
Joseph Posted November 8, 2014 Author Share Posted November 8, 2014 dude i was just lazy i ddint really want to create a new instance and have to go about using that. Rather then having it already initialize. Link to comment Share on other sites More sharing options...
NotoriousPP Posted November 8, 2014 Share Posted November 8, 2014 dude i was just lazy i ddint really want to create a new instance and have to go about using that. Rather then having it already initialize. Well that's why a lot of people including myself when I wrote scripts use the Node frame, since your able to store your method provider instance inside of the NodeWrapper, allowing you to use it throughout all your nodes, which I'm sure you already know. Though as @Swizzbeat said above, this creates a unnecessary amount of method provider instances; when in reality, you only need one, and have it passed around like a dirty whore. The less redundant instantiations, the better. 3 Link to comment Share on other sites More sharing options...