SRL Archive - Bugs

Items


Capricorn

2011-01-08 12:19:35

Procedure R_ReturnItem(Item: Variant; var ItemIDs: TIntegerArray; var ItemNames: TStringArray);
var
ItemIDArray: TIntegerArray;
ItemNameArray: TStringArray;
I, arrC: Integer;
begin

ItemIDArray := [];
ItemNameArray := [];

SetArrayLength(ItemIDs, 1000);
SetArrayLength(ItemNames, 1000);

case VarType(Item) of
varInteger: For I:=0 to High(ItemIDs) do
if (ItemIDArray[I] = Item) then
begin
ItemIDs[arrC] := Item;
ItemNames[arrC] := ItemNameArray[I];
Inc(arrC);
end;

varString: For I:=0 to High(ItemIDs) do
if (LowerCase(ItemNameArray[I]) = LowerCase(Item)) then
begin
ItemIDs[arrC] := ItemIDArray[I];
ItemNames[arrC] := Item;
Inc(arrC);
end;
else
writeln ('[R_ReturnItem] Warning: Unsupported data type (you must enter an integer or string)');
end;
SetArrayLength(ItemIDs, arrC);
SetArrayLength(ItemNames, arrC);
end;

This is broken, after you go to far in the array (past 1000 I would imagine) it always returns -1 or '' depending if you want the ID or name.

It works if you set
  SetArrayLength(ItemIDs, 1000);
SetArrayLength(ItemNames, 1000);
to
  SetArrayLength(ItemIDs, 3334);
SetArrayLength(ItemNames, 3334);
However that requires the person to change that every time new items are added so perhaps

  SetArrayLength(ItemIDs, GetArrayLength(ItemIDArray));
SetArrayLength(ItemNames, GetArrayLength(ItemNameArray));
Would be better.

(I think you may have to subtract one from GetArrayLength, not sure :))

Dgby714

2011-01-08 12:31:36

I think this function just broke my brain….

You set ItemIDArray and ItemNameArray to empty then loop thru another array checking these.
I don't think its possible not to get a "Error: Out Of Range" without passing empty arrays.

E: ahh…

Capricorn

2011-01-08 12:33:14

From: Dgby714
I think this function just broke my brain….

You set ItemIDArray and ItemNameArray to empty then loop thru another array checking these.
I don't think its possible not to get a "Error: Out Of Range" without passing empty arrays.


They aren't empty, they each have 3334 elements in them (at the moment).

I excluded them because I didn't feel it was necessarily to clutter the procedure up with them. Otherwise it would have been a huge box.

This is already a function in Reflection, it was/is just broken and I am merely pointing that out and what I did to make it work. Maybe you know a better way of doing what the function does?