SRL Archive - OSR Help

For..To..Do


DeSnob

2010-10-30 09:37:25

For the past few days much of my free time has been spent working on a little project of mine. Whether it will be completed or not is another story. Currently problems are already being encountered when trying to run through a for..to..do loop. I need the bot to randomly choose the skin color, but first it needs to detect the current skin color. So I set this up:
function SSkin: boolean;
var
GPos: Array of TPoint;
i, Skin: Integer;
begin
GPos[0] := Point(487, 27);
GPos[1] := Point(507, 27);
GPos[2] := Point(530, 27);
GPos[3] := Point(558, 27);
GPos[4] := Point(563, 27);
GPos[5] := Point(587, 27);
GPos[6] := Point(614, 27);
GPos[7] := Point(640, 27);
GPos[8] := Point(663, 27);
GPos[9] := Point(687, 27);
GPos[10] := Point(713, 27);
GPos[11] := Point(739, 27);
for i:= 0 to 11 do
begin
if (CountColorTolerance(14859158, GPos[i].x, GPos[i].y, GPos[i].x+1, GPos[i].y+1, 3) > 0) then
Constant := GPos[i];
else
Continue;
end;
end;
[BANANA]*NOTE: Constant is a global variable in my script-
Constant: variant;
It will be used to save the current coords where the outline color is found.
[/BANANA]
Technically it should compile. However, my rusty scripting is at fault. I do not understand why it does not work!(Gives me a runtime error.) Could someone please explain to me please? There is no need for code snippets unless it is an example. I'll include credits where it is needed to whoever helps me out. :)

HyperSecret

2010-10-30 09:47:42

What line of code do you get the runtime error at? Do a little debugging to find your problem.

ZephyrsFury

2010-10-30 10:16:47

You have to set the length of your array first perhaps.


SetLength(GPos, 12)

Dgby714

2010-10-30 10:33:14

You need to SetLength, when your at the end of a for loop there is no reason to do continue, and when you exclude begin end inside of a if else you remove the ; after the command before else.

Not realy needed but Array of TPoint can be TPointArray
There was also no use for the integer Skin

function SSkin: boolean;
var
GPos: TPointArray;
i: Integer;
begin
SetArrayLength(GPos, 12);
GPos[0] := Point(487, 27);
GPos[1] := Point(507, 27);
GPos[2] := Point(530, 27);
GPos[3] := Point(558, 27);
GPos[4] := Point(563, 27);
GPos[5] := Point(587, 27);
GPos[6] := Point(614, 27);
GPos[7] := Point(640, 27);
GPos[8] := Point(663, 27);
GPos[9] := Point(687, 27);
GPos[10] := Point(713, 27);
GPos[11] := Point(739, 27);
for i:= 0 to 11 do
if (CountColorTolerance(14859158, GPos[i].x, GPos[i].y, GPos[i].x+1, GPos[i].y+1, 3) > 0) then
Constant := GPos[i];
end;

DeSnob

2010-10-30 12:27:17

From: Dgby714
You need to SetLength, when your at the end of a for loop there is no reason to do continue, and when you exclude begin end inside of a if else you remove the ; after the command before else.

Not realy needed but Array of TPoint can be TPointArray
There was also no use for the integer Skin

function SSkin: boolean;
var
GPos: TPointArray;
i: Integer;
begin
SetArrayLength(GPos, 12);
GPos[0] := Point(487, 27);
GPos[1] := Point(507, 27);
GPos[2] := Point(530, 27);
GPos[3] := Point(558, 27);
GPos[4] := Point(563, 27);
GPos[5] := Point(587, 27);
GPos[6] := Point(614, 27);
GPos[7] := Point(640, 27);
GPos[8] := Point(663, 27);
GPos[9] := Point(687, 27);
GPos[10] := Point(713, 27);
GPos[11] := Point(739, 27);
for i:= 0 to 11 do
if (CountColorTolerance(14859158, GPos[i].x, GPos[i].y, GPos[i].x+1, GPos[i].y+1, 3) > 0) then
Constant := GPos[i];
end;


Problem solved! My variant variable does not want to work with TPoints, so I created a local var to take care of business. Thanks to you and ZephyrsFury not only did my problem go away, but I also have neater code. :)

Nava2

2010-10-30 15:59:37

Why not declare it using the X = [x1, x2] syntax?

It cleans up your code, as well it allows you to quickly add points. Also, in your for loop, adding in high(X) rather than using static numbers might be a good plan.

DeSnob

2010-10-30 17:44:10

Thanks Nava2, here's my procedure so far:
{SelectSkin- Thanks to Dgby714, ZephyrsFury, and Nava2 for help with this}
procedure SSkin;
var
GPos: TPointArray;
i, Skin: Integer;
C : TPoint;
begin
if not(CCScreen) then
Exit;
SetLength(GPos, 12);
GPos := [Point(463, 27), Point(486, 27), Point(515, 27), Point(538, 27),
Point(561, 27), Point(587, 27), Point(614, 27), Point(640, 27),
Point(663, 27), Point(687, 27), Point(713, 27), Point(739, 27)];
for i:= Low(GPos) to High(GPos) do
if (CountColorTolerance(14859158, GPos[i].x, GPos[i].y, GPos[i].x+1, GPos[i].y+1, 63) > 0) then
C := GPos[i];
case (C.x) of
463: Constant := 0;
486: Constant := 1;
515: Constant := 2;
538: Constant := 3;
561: Constant := 4;
587: Constant := 5;
614: Constant := 6;
640: Constant := 7;
663: Constant := 8;
687: Constant := 9;
713: Constant := 10;
739: Constant := 11;
end;
Skin := Random(11);
if (Skin = Constant) then
if (Constant = 11) then
Dec(Skin)
else
if (Constant > -1) then
Inc(Skin);
Mouse(GPos[Skin].x, GPos[Skin].y+2+random(4), 5, 5, True);
Wait(356+random(653));
end;
The case seems large, I'll see what I can do with it. :)
E:
{SelectSkin- Thanks to Dgby714 and ZephyrsFury for help with this}
procedure SSkin;
var
GPos: TPointArray;
i, Skin: Integer;
SkinID: TIntegerArray;
C : TPoint;
begin
if not(CCScreen) then
Exit;
SetLength(GPos, 12);
GPos := [Point(463, 27), Point(486, 27), Point(515, 27), Point(538, 27),
Point(561, 27), Point(587, 27), Point(614, 27), Point(640, 27),
Point(663, 27), Point(687, 27), Point(713, 27), Point(739, 27)];
SetLength(SkinID, 12);
SkinID := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
for i:= Low(GPos) to High(GPos) do
if (CountColorTolerance(14859158, GPos[i].x, GPos[i].y, GPos[i].x+1, GPos[i].y+1, 63) > 0) then
begin
C := GPos[i];
Constant := SkinID[i];
end;
Skin := Random(11);
if (Skin = Constant) then
if (Constant = 11) then
Dec(Skin)
else
if (Constant > -1) then
Inc(Skin);
Mouse(GPos[Skin].x, GPos[Skin].y+2+random(4), 5, 5, True);
Wait(356+random(653));
end;
Made it shorter! :)

Dgby714

2010-10-30 17:56:52

procedure SSkin;
var
GPos: TIntegerArray;
i, Skin: Integer;
begin
if not(CCScreen) then
Exit;
SetLength(GPos, 12);
GPos := [463, 486, 515, 538, 561, 587, 614, 640, 663, 687, 713, 739];
for i := Low(GPos) to High(GPos) do
if (CountColorTolerance(14859158, GPos[i], 27, GPos[i] + 1, 28, 63) > 0) then
Constant := i;
Skin := Random(11);
if (Skin = Constant) then
if ((Constant > -1) and (not (Constant = 11))) then
Inc(Skin)
else
Dec(Skin);
Mouse(GPos[Skin], 29, 5, 9, True);
Wait(356 + Random(653));
end;

DeSnob

2010-10-30 20:52:58

Thank you very much.

Cstrike

2010-10-30 21:04:48

Just out of curiosity:

SetLength(GPos, 12); // <--
GPos := [463, 486, 515, 538, 561, 587, 614, 640, 663, 687, 713, 739];
Should it not work if we eliminated the top line? I might be wrong… IIRC defining a TypeArray set it's length automatically?

DeSnob

2010-10-30 21:13:22

From: cstrike
Just out of curiosity:

SetLength(GPos, 12); // <--
GPos := [463, 486, 515, 538, 561, 587, 614, 640, 663, 687, 713, 739];
Should it not work if we eliminated the top line? I might be wrong… IIRC defining a TypeArray set it's length automatically?


That was an issue before, but yes theoretically it should work without it.