SRL Archive - Outdated Tutorials

[#36] CountItems and ClickAllItems


ZephyrsFury

2009-07-04 19:07:20

Small change, two params were switched around to make it match other similar functions:

Old:

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

and

function ClickAllItems(Identifier: Integer; ItemType, option: string; waitnum: Integer; tol: TIntegerArray):Integer;


New:


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

and

function ClickAllItems(ItemType: String; Identifier: Integer; option: string; waitnum: Integer; tol: TIntegerArray):Integer;

ItemType and Identifier have been switched around. If your script complains about a type mismatch error with CountItems or ClickAllItems(Except) then switch your params around:

For example:

Change:

C := CountItems(LogDTM, 'dtm', []);

to:


C := CountItems('dtm', LogDTM, []);

Simple? Any objections btw?

"Da EssArrEll Devz"

Floor66

2009-07-04 20:47:02

Kwlkwl, gdgd!
But why was it changed? Confuzzled peeps?

ShowerThoughts

2009-07-04 20:50:24

The developers must always be active.
They are not lazy after all. ;)

Sir R. M8gic1an

2009-07-04 21:29:45

From: Floor66
Kwlkwl, gdgd!
But why was it changed? Confuzzled peeps?


To match similar functions, not because people were confused, but to make it easier in general, as now the params are in the same order.

~RM

Floor66

2009-07-04 21:34:43

Alright thanks :)

ZephyrsFury

2009-07-04 21:36:17

From: Hermen
The developers must always be active.
They are not lazy after all. ;)


I'm fast becoming lazy, d/w.

marpis

2009-07-09 10:57:38

I think the older one was better…

ZephyrsFury

2009-07-09 11:39:50

From: marpis
I think the older one was better…


Why? Any particular reason?

Sabzi

2009-07-09 13:19:23

If I can say I am totally agree with this. When I was trying out/learning SRL I found confusing that similar functions were different in this. I like the logical way! And this is it. Hope it did not sound like a spam :/

Nava2

2009-07-09 17:03:13

I did it because when I originally changed all thaw functions around, those two were already setup.

I just forgot to switch them and it had been bugging me for quite awhile.

marpis

2009-07-10 20:05:29

From: marpis
I think the older one was better…


i think the order of the parameters was more logical

ZephyrsFury

2009-07-10 20:12:20

From: marpis
i think the order of the parameters was more logical


I think this new order is more logical - 1st param: What it is, 2nd: What we're looking for, 3. info to help us look. Besides it now matches with CountItemsIn and ItemAmount.

Gu3st...

2009-07-10 22:07:32

From: ZephyrsFury
I think this new order is more logical - 1st param: What it is, 2nd: What we're looking for, 3. info to help us look. Besides it now matches with CountItemsIn and ItemAmount.

Isn't param 1 and param 2 the same? :p

Anyway: It's ok for me, but it will break alot of scripts :/

Boreas

2009-07-11 00:58:53

From: Zyt3x
Isn't param 1 and param 2 the same? :p

Anyway: It's ok for me, but it will break alot of scripts :/

Try this
program New;

var
pt1,pt2,pt3,TheFile:integer;
str1,str2,TheScriptString, TheScriptPath:string;
begin
TheScriptPath := Readln('Full path of script you would like to fix (I suggest you use a copy)');
TheFile:=OpenFile(TheScriptPath,true);
ReadFileString(TheFile,TheScriptString,Filesize(thefile));
CloseFile(TheFile);
TheScriptString:=lowercase(TheScriptString);

pt1:=1;
repeat
pt1 := PosEx(lowercase('CountItems('), TheScriptString, pt1+1);
if pt1>0 then
begin
pt2 := PosEx(',', TheScriptString, pt1);
str1:= copy(TheScriptString,pt1+11,pt2-pt1-11);
pt3 := PosEx(',', TheScriptString, pt2+1);
str2:= copy(TheScriptString,pt2+1,pt3-pt2-1);
Delete(TheScriptString, pt1+11,pt3-pt1-11);
insert(str2+','+str1,TheScriptString,pt1+11);
end;
until pt1<1;

pt1:=1;
repeat
pt1 := PosEx(lowercase('ClickAllItems('), TheScriptString, pt1+1);
if pt1>0 then
begin
pt2 := PosEx(',', TheScriptString, pt1);
str1:= copy(TheScriptString,pt1+14,pt2-pt1-14);
pt3 := PosEx(',', TheScriptString, pt2+1);
str2:= copy(TheScriptString,pt2+1,pt3-pt2-1);
Delete(TheScriptString, pt1+14,pt3-pt1-14);
insert(str2+','+str1,TheScriptString,pt1+14);
end;
until pt1<1;

TheFile:=ReWriteFile(TheScriptPath,true);
WriteFileString(TheFile,TheScriptString);
CloseFile(TheFile);
end.

Edit: Somebody wanna change this so that it automatically fixes all scripts in a directory, and also saves the original as ScriptName.scar.OLD rather than rewriting?

ZephyrsFury

2009-07-11 12:19:54

From: Zyt3x
Isn't param 1 and param 2 the same? :p

Anyway: It's ok for me, but it will break alot of scripts :/


The same?

And yes it might break a few scripts. But we either change this or change CountItemsIn, ItemAmount, FindItem, FindItemEx and all the other ones.

ShowerThoughts

2009-07-11 12:44:41

From: ZephyrsFury
The same?

And yes it might break a few scripts. But we either change this or change CountItemsIn, ItemAmount, FindItem, FindItemEx and all the other ones.


?
Are you going to change more?

ZephyrsFury

2009-07-11 13:20:16

From: Hermen
?
Are you going to change more?


Nope.

Gu3st...

2009-07-11 15:26:50

From: ZephyrsFury
The same?

And yes it might break a few scripts. But we either change this or change CountItemsIn, ItemAmount, FindItem, FindItemEx and all the other ones.

Yeah: 1st param: What it is, 2nd What we're looking for,
What we're looking for is the same as what it is and vice versa :P
It was meant as a joke so dw

Boreas

2009-07-13 08:32:47

And even if more functions are broken, the fixer script above is easy to modify.