# Hoppable Worlds Array

## Recommended Posts

```public static int[] WORLDS = {301, 302, 303, 304, 305, 306, 308, 309, 310, 311, 312,
313, 314, 316, 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, 365, 366, 367, 368, 369, 370, 373, 374, 375, 376, 377,
378};
```

And to hop to a random one:

```new WorldHopper(MethodProvider).hopWorld(WORLDS[random(WORLDS.length)]);
```

Had to make this last night and might save someone a couple minutes

This list CONTAINS F2P worlds: 308, 316

This list DOES NOT CONTAIN PvP worlds: 325, 337

Edited by Swizzbeat
• 1
##### Share on other sites

What is when random(WORLDS.length) = 0 is ? You subtract 1 then its -1. A array with -1 is impossible.

Don't subtract 1 then it will work.

Edited by Soldtodie
##### Share on other sites

What is when random(WORLDS.length) = 0 is ? You subtract 1 then its -1. A array with -1 is impossible.

Don't subtract 1 then it will work.

The first index of an array is zero, however the length method returns the total number of items in the array not taking this into account.

##### Share on other sites

The first index of an array is zero, however the length method returns the total number of items in the array not taking this into account.

He's actually right though, the random function's max is exclusive, so it already goes from 0 - max-1

##### Share on other sites

You can test it.

```		int test = -999;
while((test = random(WORLDS.length)-1) != -1) {

}
log("It's " + test + " !");
```
##### Share on other sites

He's actually right though, the random function's max is exclusive, so it already goes from 0 - max-1

Hmm I always thought the random method started at 1 my apologies then, I'll fix now. Thanks to both

• 1
##### Share on other sites

You have to subtract by one, the length of an array with one object is 1, while the object index is 0. If the random method returns the length of this array it will give you a nullpointer as the object that has the index of the length doesnt exist (in short words: the lenght of an array is its total objects +1)

##### Share on other sites

You have to subtract by one, the length of an array with one object is 1, while the object index is 0. If the random method returns the length of this array it will give you a nullpointer as the object that has the index of the length doesnt exist (in short words: the lenght of an array is its total objects +1)

Hmm so my original code was right I just need to add a min/max value in....I'll fix when I get on a computer!
##### Share on other sites

Your code is too broad and it doesn't take into consideration potential latency issues someone may experience, e.g., I don't play on American servers because there would be too much latency at times. If I were to bot, this would undoubtedly effect the bot's performance.

##### Share on other sites

Your code is too broad and it doesn't take into consideration potential latency issues someone may experience, e.g., I don't play on American servers because there would be too much latency at times. If I were to bot, this would undoubtedly effect the bot's performance.

This is just an array for all the possible worlds people can hop to without the PvP ones. I don't think anyone really cares if their on an American/Germany server :p

##### Share on other sites

```new WorldHopper(MethodProvider).hopWorld(WORLDS[random(WORLDS.length - 1)]);
```

No need to put the 0 in there. ^_^

##### Share on other sites

`new WorldHopper(MethodProvider).hopWorld(WORLDS[random(WORLDS.length - 1)]);`
No need to put the 0 in there. ^_^
Fixed it right after I changed it :p it's 2 in the morning my brains a little loopy!
• 1
##### Share on other sites

An instance of WorldHopper is already accessible from MethodProvider.

`MethodProvider#worldHopper`
##### Share on other sites

Thanks for this

Alot of people might want to remove the f2p worlds, though

##### Share on other sites

Sorry but this is not right:

```random(WORLDS.length() - 1)
```

An example:

random(28);

This can gives you the number 0 or the number 27 and all numbers beetween this two numbers. But not the number 28.

This is right:

`random(WORLDS.length())`