Jump to content

World hopping


Recommended Posts

Posted

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.

Posted

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.

Posted

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();
    }

 

Posted

        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();

Posted
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.

Posted (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 by SatanicHammer

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...