SRL Archive - SRL Bugs

[Fix] R_ReturnItem


Emaziz

2011-02-16 10:57:26

Small disfunction at R_ReturnItem, fixed with a quick fix! :)

Current function is:
{*******************************************************************************
function R_ReturnItem (NameOrID : Variant) : Variant;
By: pyroryan [database, aka: hard work], Cstrke [code, aka easy work]
Description: Input item name/ID to get back ID/item name.
*******************************************************************************}
Procedure R_ReturnItem(Item: Variant; var ItemIDs: TIntegerArray; var ItemNames: TStringArray);
var
ItemIDArray: TIntegerArray;
ItemNameArray: TStringArray;
I, arrC: Integer;
begin

//ItemIDArray
//ItemNameArray
//Removed because they are HUGE.

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;
And the above function will not be able to return items above array index of 1000, because of
SetArrayLength(ItemIDs, 1000);
SetArrayLength(ItemNames, 1000);
That is bad. :(
But here's how it should be!
SetArrayLength(ItemIDs, high(ItemIDArray));
SetArrayLength(ItemNames, high(ItemNameArray));

Gu3st...

2011-02-16 13:33:41

high(ItemIDArray) and high(ItemNameArray) would both return -1, as ItemIDArray and ItemNameArray aren't defined anywhere…

Emaziz

2011-02-16 16:58:01

From: Zyt3x
high(ItemIDArray) and high(ItemNameArray) would both return -1, as ItemIDArray and ItemNameArray aren't defined anywhere…


They are defined.
ItemIDArray := [HUGEARRAY]
ItemNameArray := [HUGEARRAY]

I didn't post them because they are huge.

Gu3st...

2011-02-16 16:58:53

From: Emaziz
*Sigh*

They are defined.
ItemIDArray := [HUGEARRAY]
ItemNameArray := [HUGEARRAY]

I didn't post them because they are huge.
Oh, I see… You posted that comment.. :redface:

Well, then I support your fix :)