SatanicHammer Posted May 22, 2020 Posted May 22, 2020 Hey I'm new to the bot scene and I'm currently struggling with a nullpointerexception. Quote public static void HopWorldRandom() throws InterruptedException { int CurrentWorld = script.getWorlds().getCurrentWorld(); int HoptoWorld = WORLDS[MethodProvider.random(WORLDS.length)]; while(CurrentWorld == HoptoWorld) { HoptoWorld = WORLDS[MethodProvider.random(WORLDS.length)]; } final int HoptoWorldfinal = HoptoWorld; script.log("Hopping to world: "+HoptoWorld); if(script.worlds.hop(HoptoWorld)) new ConditionalSleep(MethodProvider.random(10000, 10000)) { @Override public boolean condition() throws InterruptedException { return CurrentWorld == HoptoWorldfinal; } }.sleep(); } It works for a couple of hours before I get a nullpointerexception and then it doesn't, any ideas? WORLDS[] is simply an array of worlds to choose from when randomly hopping.
SatanicHammer Posted May 22, 2020 Author Posted May 22, 2020 I think I found a bug, I'm trying this now and so far so good: Quote public static void HopWorldRandom() throws InterruptedException { int CurrentWorld = script.getWorlds().getCurrentWorld(); int HoptoWorld = WORLDS[MethodProvider.random(WORLDS.length-1)]; while(CurrentWorld == HoptoWorld) { HoptoWorld = WORLDS[MethodProvider.random(WORLDS.length-1)]; } final int HoptoWorldfinal = HoptoWorld; script.log("Hopping to world: "+HoptoWorld); if(script.worlds.hop(HoptoWorld)) new ConditionalSleep(MethodProvider.random(10000, 10000)) { @Override public boolean condition() throws InterruptedException { return CurrentWorld == HoptoWorldfinal; } }.sleep(); } Any tips on how to detect if I've hopped world? return CurrentWorld == HoptoWorldfinal; Is really slow.
SatanicHammer Posted May 22, 2020 Author Posted May 22, 2020 Solved it I think, here's the final code if someone needs it in the future: Quote public static void HopWorldRandom() throws InterruptedException { int CurrentWorld = script.getWorlds().getCurrentWorld(); int HoptoWorld = WORLDS[MethodProvider.random(WORLDS.length-1)]; while(CurrentWorld == HoptoWorld) { HoptoWorld = WORLDS[MethodProvider.random(WORLDS.length-1)]; } final int HoptoWorldfinal = HoptoWorld; script.log("Hopping to world: "+HoptoWorld); if(script.worlds.hop(HoptoWorld)) new ConditionalSleep(10000, MethodProvider.random(1000, 2000)) { @Override public boolean condition() throws InterruptedException { return CurrentWorld == HoptoWorldfinal; } }.sleep(); }
Camaro Posted May 22, 2020 Posted May 22, 2020 new ConditionalSleep(MethodProvider.random(10000, 10000)) { @Override public boolean condition() throws InterruptedException { return CurrentWorld == HoptoWorldfinal; } }.sleep(); that will never work since you never update the values. do this instead new ConditionalSleep(MethodProvider.random(10000, 10000)) { @Override public boolean condition() throws InterruptedException { return script.getWorlds().getCurrentWorld() == HoptoWorldfinal; } }.sleep();
SatanicHammer Posted May 22, 2020 Author Posted May 22, 2020 10 minutes ago, Camaro said: new ConditionalSleep(MethodProvider.random(10000, 10000)) { @Override public boolean condition() throws InterruptedException { return CurrentWorld == HoptoWorldfinal; } }.sleep(); that will never work since you never update the values. do this instead new ConditionalSleep(MethodProvider.random(10000, 10000)) { @Override public boolean condition() throws InterruptedException { return script.getWorlds().getCurrentWorld() == HoptoWorldfinal; } }.sleep(); That is true, Thanks! I don't think this will will solve the nullpointerexception error but it's a step in the right direction.
SatanicHammer Posted May 23, 2020 Author Posted May 23, 2020 (edited) ava.lang.NullPointerException at org.osbot.rs07.api.Worlds.iiiiIiiIIIIi(lf:97) at org.osbot.rs07.api.Worlds.IIIiiiiIIIii(lf:215) at org.osbot.rs07.api.Worlds.hop(lf:301) at MyPackage.task.MyMethodProvider.HopWorldRandom(MyMethodProvider.java:157) at MyMainClass.task.MyClass.execute(MyClass.java:78) at MyPackage.MyMainClass.onLoop(MyMainClass.java:43) at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(ch:146) at java.lang.Thread.run(Unknown Source) Edited May 23, 2020 by SatanicHammer