SRL Archive - Help and Support

Suggestions for Script Speed please?


Sir Ducksworthy

2012-04-12 13:44:44

I'm aiming for Ghetto Bot to be a Low Memory Consuming script if anyone has any Suggestions to make this better It'd be appreciated.

I was thinking of probably moving from a case to just different Procedures and then Assigning it to another procedure in the Main Loop During Setup so It would only need to Do 1 Computation Each time instead of Going through a whole case.

  //New method for me Approaching multiple Different TPA's
//Trying to Avoid more Computations
'Cow':
begin
repeat
if(FindTpa(HueModifier, SatModifier, 15, 15, Color,
Tol, xx1, yy1, xx2, yy2, Text, ['ttack']))then
break;
if(FindTpa(HueModifier2, SatModifier2, 15, 15,
Color2, Tol2, xx1, yy1, xx2, yy2, Text, ['ttack']))then
break;
if(FindTpa(HueModifier3, SatModifier3, 15, 15, Color3, Tol3,
xx1, yy1, xx2, yy2, Text, ['ttack']))then
break;
if(FindTpa(HueModifier4, SatModifier4, 15, 15,Color4, Tol4,
xx1, yy1, xx2, yy2, Text, ['ttack'])) then
break; //If one of these ^ break's are used it means Found is True
NotFound:=True; //Using this to Avoid one more Computation at the start
break; //Since NotFound is Automatically False by default when The Var is Declared at the start
until(false);
end;

Yago

2012-04-12 13:49:16

why do you need a repeat loop? just use else if

Edit:


you could do:
NotFound := not (findtpa(color1) or findtpa(color2) or findtpa(color3)…);

Sir Ducksworthy

2012-04-12 14:13:22

O kool I had the idea in my head that Id need to set a Boolean using that but, I didn't realise I could do the exact same thing like this:
 
'Cow':
begin
if(not(FindTpa(HueModifier, SatModifier, 15, 15, Color,
Tol, xx1, yy1, xx2, yy2, Text, ['ttack'])))then
else if(not(FindTpa(HueModifier2, SatModifier2, 15, 15,
Color2, Tol2, xx1, yy1, xx2, yy2, Text, ['ttack'])))then
else if(not(FindTpa(HueModifier3, SatModifier3, 15, 15, Color3, Tol3,
xx1, yy1, xx2, yy2, Text, ['ttack'])))then
else if(not(FindTpa(HueModifier4, SatModifier4, 15, 15,Color4, Tol4,
xx1, yy1, xx2, yy2, Text, ['ttack']))) then
NotFound:=True;
end;

Thx!

Yago

2012-04-12 14:36:59

From: leetsxc
O kool I had the idea in my head that Id need to set a Boolean using that but, I didn't realise I could do the exact same thing like this:
 
'Cow':
begin
if(not(FindTpa(HueModifier, SatModifier, 15, 15, Color,
Tol, xx1, yy1, xx2, yy2, Text, ['ttack'])))then
else if(not(FindTpa(HueModifier2, SatModifier2, 15, 15,
Color2, Tol2, xx1, yy1, xx2, yy2, Text, ['ttack'])))then
else if(not(FindTpa(HueModifier3, SatModifier3, 15, 15, Color3, Tol3,
xx1, yy1, xx2, yy2, Text, ['ttack'])))then
else if(not(FindTpa(HueModifier4, SatModifier4, 15, 15,Color4, Tol4,
xx1, yy1, xx2, yy2, Text, ['ttack']))) then
NotFound:=True;
end;

Thx!


you could also use or statements…

if not (this or that or thisthat) then NotFound := True;

Sir Ducksworthy

2012-04-12 15:41:28

Yeh, last time I used them they weren't cycling for me properly tho for me it was like choosing one Randomly out of them it seemed.

nickrules

2012-04-12 15:56:42

From: leetsxc
Yeh, last time I used them they weren't cycling for me properly tho for me it was like choosing one Randomly out of them it seemed.


It should do them in order. Here's an example:

program new;
function a:boolean;
begin
result:=true;
writeln('A is true!');
end;

function b:boolean;
begin
result := false;
writeln('function b is false, and called second!');
end;

function c:boolean;
begin
result:= true;
writeln('Function C is true, and third!');
end;

begin
if a or b or c then
begin
writeln('one of the above is true!');
end else
writeln('all of the above are false!');
end.

Run like this, you'll get:
Compiled successfully in 0 ms.
A is true!
one of the above is true!
Successfully executed.
but if you set a to false, then you get:
Compiled successfully in 16 ms.
A is true!
function b is false, and called second!
Function C is true, and third!
one of the above is true!
Successfully executed.

What this means, is that the moment *one* of those are true, it doesn't bother checking any of the others.

mormonman

2012-04-12 15:57:24

Make them arrays and then use them like this:

'Cow':
begin
NotFound := False;
for i := 0 to High(Length) do
if(FindTpa(HueModifier[i], SatModifier[i], 15, 15, Color[i],
Tol[i], xx1, yy1, xx2, yy2, Text, ['ttack']))then
Exit;
NotFound := True;
end;

Sir Ducksworthy

2012-04-12 21:14:19

Thx Mormonman Rep+ That was an awesome suggestion I changed a ton of things in to array's now even added the Pot Timer and the Break Timer into 1 array lolz
Look's like this now ;))

  For i := 0 to High(Color) do
begin
if(FindTpa(HueModifier[i], SatModifier[i], 10, 10, Color[i], Tol[i], TPASearchArea[0], TPASearchArea[1],
TPASearchArea[2], TPASearchArea[3], Text, ['ttack']))then break;
if(i = High(Color))then
NotFound:=true;
end;