Jump to content

World hopping


SatanicHammer

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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