SRL Archive - OSR Help

Help with arrays and switching worlds


Cage

2014-06-18 19:57:24

Hello all, I am trying to figure out how I can effectively switch worlds based on my array list of worlds. I know there is already world hopping functions available, but I wan't to only go to the worlds on this list.

I wan't my script to log into the first world in this array, and if certain conditions are not met, I wan't my player to log out and go and move on to the next world in my array list. Hope that makes sense?

Any and all help would be greatly appreciated!

procedure WorldHandler;
begin
SetLength(WorldNumber, 55);
WorldNumber := [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];


Help needed here.


end;

KeepBotting

2014-06-18 20:00:10

I'm not familiar with SRL-OSR's login/world/lobby/whatever routines, but the basic concept is outlined pretty well in my worldSwitcher snippet. Even though it's written for RS3, the logic is what's important.

Link is in my signature, add me on Skype if you need additional help.

Wetish

2014-06-18 20:50:37

Use a global variable to keep track of what world you are on.

program new;
{$I SRL-OSR/SRL.Simba}
Var
WorldNumber:TIntegerArray;
WorldCounter:Integer;

procedure SwitchWorld;
begin
//Switch to a world based on the WorldCounter
WriteLn('Changing to world ' + tostr(WorldNumber[WorldCounter]));
ChangeWorld(WorldNumber[WorldCounter]);

//Increase the WorldCounter for the next time we switch
WorldCounter := WorldCounter +1; //I don't remember how to use ++ with pascal

//Check to make sure we don't go out of bounds in the array. If the counter is too high we should reset it back to 0.
if (WorldCounter > high(WorldNumber)) then
WorldCounter := 0;

end;


begin
WorldNumber := [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];
SwitchWorld;

end.

KeepBotting

2014-06-18 20:53:26

From: Wetish
Use a global variable to keep track of what world you are on.

program new;
{$I SRL-OSR/SRL.Simba}
Var
WorldNumber:TIntegerArray;
WorldCounter:Integer;

procedure SwitchWorld;
begin
//Switch to a world based on the WorldCounter
WriteLn('Changing to world ' + tostr(WorldNumber[WorldCounter]));
ChangeWorld(WorldNumber[WorldCounter]);

//Increase the WorldCounter for the next time we switch
WorldCounter := WorldCounter +1; //I don't remember how to use ++ with pascal

//Check to make sure we don't go out of bounds in the array. If the counter is too high we should reset it back to 0.
if (WorldCounter > high(WorldNumber)) then
WorldCounter := 0;

end;


begin
WorldNumber := [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];
SwitchWorld;

end.
inc(x); in pascal is the same as x++; in java

The Mayor

2014-06-18 20:58:20

so something like


program new;
{$I SRL-OSR/SRL.Simba}

var
currentIndex: integer;

procedure switchNextWorld;
var
worldList: TIntegerArray;
begin

worldList := [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];

if currentIndex = high(worldList) then
currentIndex := 0
else
inc(currentIndex);

if loggedIn then
waitFunc(@Logout, 500, 5000);

selectWorld(worldList[currentIndex]);
loginPlayer;
end;

begin
currentIndex := 0;

end.

slacky

2014-06-19 12:02:23

From: KeepBotting
inc(x); in pascal is the same as x++; in java

No it's not. The post increment operator (i++) will return the current value then increase it.

int i = 0;
System.out.println(i++); /* writes: 0 */
System.out.println(i); /* writes: 1 */

int i = 0;
System.out.println(++i); /* writes: 1 */
System.out.println(i); /* writes: 1 */

In Lape Inc(i) is the same as the pre-increment ++i.. which increases first then returns it.

In PascalScript (engine used with SRL-OSR) Inc(i), does not return anything.

As of next Simba release I think Lape will have an alternative to the Inc(i): Compound assignment ops -> i += 1

rj

2014-06-19 12:34:01

From: KeepBotting
inc(x); in pascal is the same as x++; in java


All Inc(x) is this:


Procedure inc(var x:integer);
Begin
X := X + 1;
End;
Thus not the same as java