SRL Archive - Reflection Help

[Error] FindObjectsEx returns True but no tile?


Runescapian321

2009-08-23 05:29:03

[Runtime Error] : Out Of Range in line 174 in script C:\Program Files\SCAR 3.21\includes\SRL\SRL\Reflection\Objects.Scar

{*******************************************************************************
Function FindObjectEx(Var Tile: TPoint; objType, MaxLength: Integer): Boolean;
By: n3ss3s and Bobarkinator
Description: Returns True if objType is found. Tile of objType is returned in
Tile.
*******************************************************************************}
Function FindObjectEx(Var Tile: TPoint; objType, MaxLength: Integer): Boolean;
var
Tiles: TPointArray;
begin
Result := FindObjectsEx(Tiles, [objType], MaxLength);
if Result then
Tile := Tiles[0] //Line 174
else
Tile := Point(-1, -1);
end;

If there's nothing in Tiles[0], that means no tiles were returned. I haven't looked at it too closely but from a glance it seems that FindObjectsEx uses GetObjectAt on every possible tile, therefore I don't see how it could find an object without its tile?

{*******************************************************************************
function FindObjectsEx(Var Tiles: TPointArray; objTypes: TIntegerArray; MaxLength: Integer): Boolean;
By: n3ss3s, Bobarkinator and Nava2
Description: Returns True if any of the ObjTypes array is found, returns all
occurances in MaxLength.
*******************************************************************************}
function FindObjectsEx(Var Tiles: TPointArray; objTypes: TIntegerArray; MaxLength: Integer): Boolean;
// Yakman's spiral algorithm =]
var
Dir, tLength, f, X, Y, nL: Integer;
TP: TPoint;
TileObject: UID;

begin
TP := GetMyPos;
X := TP.X;
Y := TP.Y;
Dir := 0;
tLength := 1;
while (tLength < MaxLength) do
begin
for F := 0 to tLength - 1 do
begin
case Dir of
0: Dec(Y);
1: Inc(X);
2: Inc(Y);
3: Dec(X);
end;
TileObject := GetObjectAt(X, Y);
if InIntArray(objTypes, TileObject.objType) then
begin
//Writeln('Found Type ' + IntToStr(objType) + ' at X ' + IntToStr(X) +
//' Y ' + IntToStr(Y));
Result := True;
SetArrayLength(Tiles, nL + 1);
Tiles[nL] := GetObjectTile(TileObject.UID);
Inc(nL);
end else
//Writeln('X: '+IntToStr(X)+' Y:'+IntToStr(Y)+ ' '+IntToStr(TileObject.objType));
end;
Inc(Dir);
dir := dir mod 4;
if Dir mod 2 = 0 then
Inc(tLength);
end;
end;

By the way, I'm using this to find out when it has arrived at the other port when on the ship from Port Sarim -> Karamja (checks if FindObjectEx the gangplank).

mormonman

2009-08-23 05:31:44

Does it keep doing this, or just a one time thing?

Runescapian321

2009-08-23 05:44:01

Keeps happening, though only in this case (searching for the gangplank while being transferred to karamja/port sarim), as far as I know.

JAD

2009-08-23 05:52:54

Try changing it to:


{*******************************************************************************
Function FindObjectEx(Var Tile: TPoint; objType, MaxLength: Integer): Boolean;
By: n3ss3s and Bobarkinator
Description: Returns True if objType is found. Tile of objType is returned in
Tile.
*******************************************************************************}
Function FindObjectEx(Var Tile: TPoint; objType, MaxLength: Integer): Boolean;
var
Tiles: TPointArray;
begin
Result := FindObjectsEx(Tiles, [objType], MaxLength);
if Result then
if(GetArrayLength(Tiles) > 0)then
Tile := Tiles[0] //Line 174;
if(not(Result))then
Tile := Point(-1, -1);
end;

See if that works. There maybe a problem with FindObjectsEx resulting true when it shouldn't.

Runescapian321

2009-08-23 06:12:49

Thanks JAD, that will work in FindObjectEx's case, though FindObjectsEx for some reason returns true; anyone know why :confused: