SRL Archive - SRL Archives

CountItemsDTM(itemdtm: integer);


marpis

2009-01-28 16:46:08

I found the CountItems function quite hard to use, in fact, i didnt understand it. I made a simplier one, that only uses dtms (dtms are the only real usable way to find items in inventory in most cases, as we all know)

It does NOT tell you how many arrows you have or such. It DOES tell you how many logs, bones or lobsters etc you have.


function CountItemsDTM(itemdtm: Integer) : integer;
var i : integer;
Box : TBox;
begin
for i:= 1 to 28 do
begin
Box:= InvBox(i);
if ExistsItem(i) then
begin
if FindDtm(itemdtm, x, y, Box.x1, Box.y1, Box.x2, Box.y2) then
Inc(Result);
end;
end;
end;

Sir R. M8gic1an

2009-01-28 18:04:54

I don't see why this function would be included for various reasons;

definitely good practice and a good function, useful and simple to understand.

But, the one that exists in srl already does this, only to a much larger degree. It's a question of reading better, and if you don't understand it you cn always ask for help on how to use it, as there are always helpful people online, either in the help forums or in the IRC channel.

Also, SRL sort of has a "rule" that if a function is easy and simple enought (and short) to do, it does not really need to be in the include. I mean, you have a perfect use of a TBox there. Kudos. But it is also true that many people, such as yourself, could make that function if they really needed it and did not want to use the one in srl.

SRL actually used to have CountDTM and CountBMP, it was just replaced by a more global one, so this wold jsut ort of be taking a step back (which is not necssarily bad).


~RM

ZephyrsFury

2009-01-28 23:35:33

Quick tutorial:


function CountItems(identifier: Integer; identifiertype: string; tol: TIntegerArray): Integer;

Identifer is the variable that holds the bmp, bitmap mask, dtm or colour of the item you're searching for.
IdentifierType is the type of identifier obviously, that is 'dtm', 'bmp', 'bmpmask', 'color'.
Tol is an array of integers that contains information on the tolerance and the contour tolerance (in the case of bitmap masks). The length of this array can range from 0 for dtms (dtms do no need tolerance), 1 for colour and bitmaps where the value is the tolerance of the colour and the bitmap or 2 for bitmap masks where the first value is the bmp tolerance and the second value is the contour tolerance.

Examples:

DTMS:

ItemCount := CountItems(DTM, 'dtm', []); //array length is 0

Colour:

ItemCount := CountItems(65536, 'color', [10]);

Bitmaps:

ItemCount := CountItem(BMP, 'bmp' , [50]);

Bitmap Masks:

ItemCount := CountItem(BMPMask, 'bmpmask', [50, 10]);

marpis

2009-01-29 00:43:02

thanks :)