SRL Archive - OSR Help

Out of rang error


Element17

2012-07-08 17:12:40

Function Teleport(Where: String): Boolean;  //LS //Yeah I know its an include but I added some stuff
Var
Loc: TStringArray;
Points: TPointArray;
i,cts: Integer;
Begin
If(Not(LoggedIn))Then Exit;
GameTab(tab_magic);
Result := GameTab(tab_magic);
If Result Then
Begin
FindHomeTeleport(x,y);
HumanMMouse(x,y, 0,0);
ClickMouse2(True);
Writeln('Clicked Home Teleprot');
Wait(1000 +Random(500));
If LodestoneScreen Then
Begin
Writeln('Found LodeStone Screen!');
Wait(3000 +Random(500));
End;

Begin
Loc := ['Catherby', 'Ardougne', 'Lumbridge'];
Points := [Point(223, 181), Point(167, 211), Point(327, 243)];

For i := 0 To 3 Do
If Capitalize(Where) = Loc[I] Then
Begin
MMouse(Points[I].X, Points[I].Y, 2, 2);
Writeln('Teleporting');
//Writeln('Teleporting to' +Loc':'+IntToStr(i+1)));
If (WaitUptextMulti(['Teleport', 'ele', 'ort', 'lepo', 'epor'], 400)) Then
Begin
Wait(1000+Random(500));
ClickMouse2(Mouse_Left);
Result := True;
If Result Then
Begin
Writeln('Teleporting');
Exit;
End Else
Writeln('Not teleporting');
End;
End;

ColorToleranceSpeed(CTS);
End;
End;
End;

Not sure why this gives me

New window: 1248828
Compiled successfully in 842 ms.
SRL Compiled in 0 msec
Found HomeTele
Clicked Home Teleprot
Found LodeStone Screen!
Teleporting
Error: Out Of Range at line 344
The following DTMs were not freed: [SRL - Lamp bitmap, 1]
The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap, SRL - Flag bitmap]

Runaway

2012-07-08 17:20:05

What is at line 344? Try setting the lengths of Loc and Points at the beginning of the function:


// ...
If(Not(LoggedIn))Then Exit;
GameTab(tab_magic);
Result := GameTab(tab_magic);
If Result Then
Begin
SetLength(Loc, 3);
SetLength(Points, 3);
FindHomeTeleport(x,y);
// ...

Element17

2012-07-08 18:56:31

If Capitalize(Where) = Loc Then


That is the line giving me the error.

NKN

2012-07-08 19:44:07

Hmm…

Try to do this:

Function Teleport(var Where: String): Boolean;

Element17

2012-07-08 20:11:40

How would I call it then? I have
Teleport('Catherby');
but it gives me Variable expected.

Kasi

2012-07-08 20:15:43

Erm 0 based arrays and your for loop has 4, it should be 0 to 2

0, 1, 2, 3
and
0, 1, 2

Edit :

For i := 0 To 3 Do
Should be

For i := 0 To 2 Do

CephaXz

2012-07-08 20:20:05

From: pur3b100d
Erm 0 based arrays and your for loop has 4, it should be 0 to 2

0, 1, 2, 3
and
0, 1, 2

Edit :

For i := 0 To 3 Do
Should be

For i := 0 To 2 Do


This. Because it doesn't have the 4th one, hence out of range.

Element17

2012-07-08 20:20:24

From: pur3b100d
Erm 0 based arrays and your for loop has 4, it should be 0 to 2

0, 1, 2, 3
and
0, 1, 2

Edit :

For i := 0 To 3 Do
Should be

For i := 0 To 2 Do


I'll fix that and thank you. I don't know how I over looked that.

**Edit I believe that fixed the error. Repp++

Kasi

2012-07-08 20:22:49

From: 14578
I'll fix that and thank you. I don't know how I over looked that.


The best way to overcome stuff like this is using (High(array) - 1), that way you dont have to search through the whole script changing integers

Element17

2012-07-08 20:34:49

Thanks for the tip man, and again thanks for the help