SRL Archive - SRL Suggestions

Update/Change WithdrawItem/WithdrawItemEx to use TstringArray


Ixilisi

2013-01-18 09:05:00

Currently WidrawItem has the wrong documentation, it states that it uses a TStringArray, but this is incorrect, and a Type mismatch will occur.
This is due to WithdrawItemEx taking a string (it's documentation is consistent in this)

Could this be possibly updated to use a TStringArray instead, it has been practically done in a similar sort of function like in WithdrawEx.

I tried a quick edit basing it off WithdrawEx, I have not tested/compiled as im going to bed now :P It's below the old

OLD

(*
WithdrawItem
~~~~~~~~~~~~

.. code-block:: pascal

function WithdrawItem(Ident: integer; IdentType: string; Amount: integer;
UpText: TStringArray; Tol: TIntegerArray): boolean;

Withdraws an item using WithdrawItemEx, but removes the Index check.

.. note::

Author: Nava2
Last Modified: Unknown

Example:

.. code-block:: pascal

if WithdrawItem(theColor, 'color', 27, ['ew log', 'ew l'], [3]) then
CloseBank;
*)
function WithdrawItem(Ident: integer; IdentType: string; Amount: integer; UpText: String; Tol: TIntegerArray): boolean;
var
I : Integer;
begin
Result := WithdrawItemEx(Ident, IdentType, I, Amount, UpText, Tol);



NEW:

(*
WithdrawItemEx
~~~~~~~~~~~~~~

.. code-block:: pascal

function WithdrawItemEx(Ident: integer; IdentType: string; var Index: integer;
Amount: integer; UpTexts: TStringArray; Tol: TIntegerArray): boolean;

Withdraws an item from the bank by using "Ident" with tol[0]
as color tolerance, tol[1] as contour tolerance in case of bmp
masks, or the count of colors for TPA item finding.
Valid IdentTypes are all in FindItem.

Index:

The Bank Index where the item is found, must be a variable.
Speeds up future withdraws.

Amount:

Amount to withdraw from bank.

UpText:

The UpText which the function checks for.

.. note::

Author: Nava2 - modified IxilisI
Last Modified: 19/01/13

Example:

.. code-block:: pascal

if WithdrawItemEx(theColor, 'color', itemSlot, 27, ['ew','ogs'], [3]) then
CloseBank;
*)
function WithdrawItemEx(Ident: integer; IdentType: string; var Index: integer; Amount: integer; Uptexts: TStringArray; Tol: TIntegerArray): Boolean;
var
x, y: integer;
BPoint: TPoint;
BankBox: TBox;
Found: Boolean;
t: TPointArray;
label
Start;
begin
Result := False;
if not BankScreen then Exit;
FixBank;

if (Index = 0) then
begin
Start:
for Index := 1 to 50 do
begin
if FindItemEx(x, y, IdentType, Ident, BankIndexToMSBox(Index), Tol) then
begin
MMouse(x, y, 4, 4);
if (Length(Uptexts) > 0) then
if (WaitUptextMulti(Uptexts, 400)) then
begin
Writeln('Found Item at Bank Slot ' + IntToStr(Index) + '.');
Found := True;
Break;
end else
Writeln('Found Incorrect Item, Moving to new Bank Spot.');
end;
end;
end else
begin
BankBox := BankIndexToMSBox(Index);
FindColors(t, srl_outline_black, BankBox.x1, BankBox.y1, BankBox.x2, BankBox.y2);
BankBox := GetTPABounds(t);
MouseBox(BankBox.x1, BankBox.y1, BankBox.x2, BankBox.y2, mouse_move);
if (Length(Uptexts) > 0) then
if (WaitUptextMulti(Uptexts, 400)) then
Found := true
else
begin
Writeln('Item Moved from Bank Slot ' + IntToStr(Index) + ', checking bank again.');
goto Start;
end;
end;
Wait(RandomRange(200, 350));
if Found then
begin
BPoint := BankIndexToBankPoint(Index);
//Writeln(IntToStr(BPoint.x) + ', ' + IntToStr(BPoint.y));
Withdraw(BPoint.x, BPoint.y, Amount);
Result := True;
end else
begin
Index := 0;
SRL_Warn('WithdrawItem', 'Could not Find ' + IdentType + ' in Bank. [Uptext: ' + UpText + ']', Warn_AllVersions);
end;
end;

(*
WithdrawItem
~~~~~~~~~~~~

.. code-block:: pascal

function WithdrawItem(Ident: integer; IdentType: string; Amount: integer;
UpText: TStringArray; Tol: TIntegerArray): boolean;

Withdraws an item using WithdrawItemEx, but removes the Index check.

.. note::

Author: Nava2 - modified IxilisI
Last Modified: 19/01/13

Example:

.. code-block:: pascal

if WithdrawItem(theColor, 'color', 27, ['ew log', 'ew l'], [3]) then
CloseBank;
*)
function WithdrawItem(Ident: integer; IdentType: string; Amount: integer; UpTexts: TStringArray; Tol: TIntegerArray): boolean;
var
I : Integer;
begin
Result := WithdrawItemEx(Ident, IdentType, I, Amount, UpTexts, Tol);
end;

Ixilisi

2013-01-18 09:07:13

Of course I search for things after they have been posted :duh:, this has already been mentioned but never rectified: http://villavu.com/forum/showthread.php?t=90870

riwu

2013-01-18 09:12:49

Changing a parameter type would break all scripts that use the function, which is a big no-no for changes to the current SRL repo.
So we can at the very most change the doc :( (or make a new function that uses TSA)

Ixilisi

2013-01-18 09:18:49

Would this perhaps make it into SRL 6 then? I'm guessing that will support lape and hence overloading which would fix that problem