Emaziz
2011-02-16 10:57:26
Small disfunction at R_ReturnItem, fixed with a quick fix! :)
Current function is:
But here's how it should be!
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));