SRL Archive - OSR Help

Counting the number of items?


Chen Monopoly

2012-05-13 12:02:46

function Count(Item: TInventoryItem): Integer;
var
i: Integer;
N: Integer;
x: Integer;
y: Integer;
Slot: TBox;
begin
for i := 1 to 28 do
begin
Slot := InvBox(i);
if FindDTM(Item.ItemDTM, x, y, Slot.X1, Slot.Y1, Slot.X2, Slot.Y2) then
N := N + 1;
end;
Result := N;
end;

Will this work/is this relatively time efficient or is there a better way of doing it?

tehq

2012-05-13 12:04:11

(*
CountItems
~~~~~~~~~~

.. code-block:: pascal

function CountItems(ItemType: string; Identifier: Integer; tol: TIntegerArray): Integer;

Counts Items in the inventory:

- ItemType: 'dtm', 'bitmap', 'bitmap mask', 'color'
- Item: name/value of your dtm/bmp/color/bmpmask.
- Tol:

* 'dtm' - [] (dtm's can't have tolerance).
* 'bmp' - [BMPTol].
* 'color' - [COLOUR Tol, Colour Count].
* 'bmpmask' - [BMPTol, ContourTol].

.. note::

by WT-Fakawi / Sumilion

Example:

.. code-block:: pascal

numbOfItems := CountItems('dtm', TheDTM, []);

*)
function CountItems(ItemType: string; Identifier: Integer; tol: TIntegerArray): Integer;
begin
GameTab(tab_Inv);
Result := CountItemsIn('inv', ItemType, Identifier, Tol)
end;

Subliment

2012-05-13 16:04:39

Personally, I prefer this way =D
function CountInventoryDTM(DTMToCount: Integer): Integer;
var
CurrentCount, i, x, y: Integer;
Sequence: TIntegerArray;
InventorySlot: TBox;
begin
CurrentCount := 0;
Sequence := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28];
for i := 0 to 27 do
begin
InventorySlot := InvBox(Sequence[i]);
if FindDTM(DTMToCount, x, y, InventorySlot.X1, InventorySlot.Y1,
InventorySlot.X2, InventorySlot.Y2) then
begin
CurrentCount := CurrentCount + 1;
end;
end;
Result := CurrentCount;
writeln(IntToStr(CurrentCount));
FreeDTM(DTMToCount);
end;

Chen Monopoly

2012-05-13 16:28:49

That really isn't any different from the one I posted except you had different names for the variables and you used an Array of 1 to 28 instead of simply doing an integer.

I think I'll just try mine first and go with the one tehq posted if it doesn't work.

Abu

2012-05-13 16:31:59

From: scipio

I think I'll just try mine first and go with the one tehq posted if it doesn't work.


Just in case you didn't know, the on tehq posted is in the SRL Include.

Subliment

2012-05-13 16:44:53

From: abu_jwka
Just in case you didn't know, the on tehq posted is in the SRL Include.


Didn't know that… Sorry (A)
But I still learned from making that method, took me a good 15 or so minutes to figure it out.

Thanks, again