SRL Archive - SRL Archives

IsChatBoxTextLines


NCDS

2009-06-08 04:58:58

This is just a small change from Zeph's 'IsChatBoxTextAnyLine'. I only added a couple Parameter's but I find it pretty useful.


{*******************************************************************************
function IsChatBoxTextAnyLine(Text: string; Line1, Line2, TextCol: Integer): Boolean;
By: ZephyrsFury
Description: Returns true if Text with colour TextCol is found between 'Line1'
and 'Line2'.
*******************************************************************************}
function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
var
II: Integer;
begin
Result := True;
for II := Line2 downto Line1 do
if (FindChatBoxText(Text, II, TextCol)) then
Exit;
Result := False;
end;

Nava2

2009-06-08 05:44:43

Could you post the original?

NCDS

2009-06-08 05:46:28

From: Nava2
Could you post the original?



{*******************************************************************************
function IsChatBoxTextAnyLine(Text: string; TextCol: Integer): Boolean;
By: ZephyrsFury
Description: Returns true if Text with colour TextCol is found anywhere in the
chat box.
*******************************************************************************}
function IsChatBoxTextAnyLine(Text: string; TextCol: Integer): Boolean;
var
II: Integer;
begin
Result := True;
for II := 8 downto 1 do
if (FindChatBoxText(Text, II, TextCol)) then
Exit;
Result := False;
end;

Btw, nice new avvy :p

ZephyrsFury

2009-06-11 16:09:31

Added. Thanks. :)

Nadeem

2009-06-11 19:30:09

You should add in a Max and Min check, just as a fool-proof failsafe :P


function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
var
II: Integer;
begin
Result := True;
for II := Max(Line1, Line2) downto Min(Line1, Line2) do
if (FindChatBoxText(Text, II, TextCol)) then
Exit;
Result := False;
end;



~NS

ZephyrsFury

2009-06-11 19:40:04

From: Nadeem
You should add in a Max and Min check, just as a fool-proof failsafe :P


function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
var
II: Integer;
begin
Result := True;
for II := Max(Line1, Line2) downto Min(Line1, Line2) do
if (FindChatBoxText(Text, II, TextCol)) then
Exit;
Result := False;
end;



~NS


Got that :)

Nadeem

2009-06-12 01:39:58

lol IDK why, but im starting to get obsession for shortening functions today…

function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
var
I: Integer;
begin
for I := Max(Line1, Line2) downto Min(Line1, Line2) do
Result := FindChatBoxText(Text, I, TextCol);
if Result then Exit;
end;


And I also made this one to return the Line number that text is present at:

function IsChatBoxTextLines(Text: string; var L: Integer; L1, L2, Col: Integer): Boolean;
begin
for L := Max(L1, L2) downto Min(L1, L2) do
Result := FindChatBoxText(Text, L, TextCol);
if Result then Exit;
end;



~NS

Naum

2009-06-12 01:42:14

I want to beat you :):

function IsChatBoxTextLines(Text: string; var L: Integer; L1, L2, Col: Integer): Boolean;
begin
for L := Max(L1, L2) downto Min(L1, L2) do
Result := FindChatBoxText(Text, L, TextCol);
end;

Nadeem

2009-06-12 02:01:47

lol, I like it :) Although if you do not exit on the line it was True at, it'll return the wrong line number! Cuz what I did was, declare var L: Integer and at the same time using that return value as the loop's decreasing value :P



~NS

NCDS

2009-06-12 04:43:16

From: ZephyrsFury
Added. Thanks. :)


Happy to help

ZephyrsFury

2009-06-12 07:01:25

From: Nadeem
lol IDK why, but im starting to get obsession for shortening functions today…

function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
var
I: Integer;
begin
for I := Max(Line1, Line2) downto Min(Line1, Line2) do
Result := FindChatBoxText(Text, I, TextCol);
if Result then Exit;
end;


And I also made this one to return the Line number that text is present at:

function IsChatBoxTextLines(Text: string; var L: Integer; L1, L2, Col: Integer): Boolean;
begin
for L := Max(L1, L2) downto Min(L1, L2) do
Result := FindChatBoxText(Text, L, TextCol);
if Result then Exit;
end;



~NS


You're missing a set of begin and ends.


function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
var
I: Integer;
begin
for I := Max(Line1, Line2) downto Min(Line1, Line2) do
begin
Result := FindChatBoxText(Text, I, TextCol);
if Result then Exit;
end;
end;

Nadeem

2009-06-12 07:06:09

From: ZephyrsFury
You're missing a set of begin and ends.


function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
var
I: Integer;
begin
for I := Max(Line1, Line2) downto Min(Line1, Line2) do
begin
Result := FindChatBoxText(Text, I, TextCol);
if Result then Exit;
end;
end;


It works besides the begin end;, doesn't it? But dun matter :P As long as it works, its all good.



~NS

Blumblebee

2009-06-12 07:08:25

you didnt have it in the begin end nest so it would not exit until it went through all the lines, whilst zephs (with the begin end nest) exits as soon as it sees the result, saving some time ;) both work, just Zephs is a bit more efficient.

Nadeem

2009-06-12 07:12:57

Awesome :) Never knew that!



~NS

ZephyrsFury

2009-06-12 07:16:35

From: Blumblebee
you didnt have it in the begin end nest so it would not exit until it went through all the lines, whilst zephs (with the begin end nest) exits as soon as it sees the result, saving some time ;) both work, just Zephs is a bit more efficient.


Well actually it wouldn't work if you don't exit cos say for example Lines are from 1 to 8, it would search from line 8 going downto 1. If it found the text on line 4 it would set Result to True. If you exit at this point Result would remain true. However if you didn't it would keep going to line 3, 2, 1 and would set Result back to False again if the text isn't found.

Blumblebee

2009-06-12 07:30:37

orite forgot that :o haha sorry.

Janilabo

2009-06-12 13:07:31

Guys, don't forget that… Sometimes a code with lower amount of lines is definitely not better than a code with higher amount of lines.

I am pointing out to speed now, it matters much more. Every single ms matters!

Here is a great little example:

var
i, tmr, x, h: Integer;
TSA: TStringArray;

begin
SetArrayLength(TSA, 10000000);
tmr:= GetSystemTime;
for i:= 0 to High(TSA) do
Inc(x);
WriteLn('Method A: X increased from 0 to ' + IntToStr(x) + ' (took ' + IntToStr(GetSystemTime - tmr) + 'ms.)');
x:= 0;
tmr:= GetSystemTime;
h:= High(TSA);
for i:= 0 to h do
Inc(x);
WriteLn('Method B: X increased from 0 to ' + IntToStr(x) + ' (took ' + IntToStr(GetSystemTime - tmr) + 'ms.)');
SetArrayLength(TSA, 0);
end.

Now, the "IsChatBoxTextLines" function (that ZephyrsFury fixed), would be faster with higher amount of lines…

Old:

function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
var
i: Integer;
begin
for i:= Max(Line1, Line2) downto Min(Line1, Line2) do
begin
Result:= FindChatBoxText(Text, i, TextCol);
if(Result)then
Exit;
end;
end;

New:

function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
var
i, tmpMx, tmpMn: Integer;
begin
tmpMn:= Min(Line1, Line2);
tmpMx:= Max(Line1, Line2);
for i:= tmpMx downto tmpMn do
begin
Result:= FindChatBoxText(Text, i, TextCol);
if(Result)then
Exit;
end;
end;

I myself got this lesson from Ron, and I am so glad I did. :) It probably doesn't matter so much with small projects, but when you'll get around bigger projects in SCAR, you'll definitely want to get around maximum speeds. :p

-Jani

Nadeem

2009-06-12 15:46:08

lol yes, I know about that too, but never used it because we are only dealing with a maximum number of 8 lines so the at most you can save is probably 1ms? maybe it won't even make a difference :P But nevertheless it is a good strategy for larger loops.



~NS