PDA

View Full Version : Type mismatch compiling error.



jonas9513
11-30-2015, 09:04 AM
Hello I need some help to fix this.

This single line is where the Error starts.


If length(TPA) < 500 then begin


This is the function its used in.


function CheckForGame: Boolean;
var
TPA: TPointArray;
begin
FindColors(TPA, 16777215, 0, 0, 437, 318)
If length(TPA) < 500 then begin
result := false; //<-- ; added. Still wont compile
end else begin
result := true;
end;
end;


The whole script is attached here: 26940

Laquisha
11-30-2015, 09:43 AM
You are missing 2 semicolons

jonas9513
11-30-2015, 09:58 AM
Where if I may ask?

FindColors(TPA, 16777215, 0, 0, 437, 318);

Wont compile either.

Also
result := false; I have, but thats not the error.

Daniel
11-30-2015, 11:20 AM
If you are using SCAR, then the prototype of FindColors can be found here (http://wiki.scar-divi.com/FindColors). It appears you were using Simba's FindColors (http://docs.villavu.com/simba/scriptref/colourfinding.html#findcolors) function (also present in old SCAR (http://www.scar-divi.com/oldmanual/)) which is different to that of the current SCAR.

Whereas Simba will return an array of points for each time the colour is found, it appears that SCAR's FindColors function is just like FindColor (no s at the end), with the exception that it will find the first point matching a set of multiple colours, rather than just one colour.

jonas9513
11-30-2015, 11:35 AM
Thanks for the help Daniel.
However, it seems I still have compiling error no matter how I try to set it up.

I've tried the different FindColor & FindColors functions but I cant compile it anyways.

I put a Semicolon after "FindColors(TPA, 16777215, 0, 0, 437, 318)"
This gives me error at FindColors. So now I know that this is the line that is giving me error.

Daniel
11-30-2015, 11:45 AM
As mentioned, the prototype for FindColors is different than the one you are using. It is expecting the following:
FindColors(out X, Y: Integer; const Colors: TIntegerArray; const XS, YS, XE, YE: Integer)

You are giving it the following:
FindColors(out TPA: TPointArray; const Color: Integer; const XS, YS, XE, YE: Integer)

slacky
11-30-2015, 11:46 AM
Expanding on what Daniel said:

There are very notable changes from ~3.3 to 3.4.x (current), in that little snippet there it's enough to replace FindColors with FindColorEx.
But I'd assume your run into more issues, perhaps simplest to just search for the SCAR version that script was made for.

jonas9513
11-30-2015, 11:56 PM
As mentioned, the prototype for FindColors is different than the one you are using. It is expecting the following:
FindColors(out X, Y: Integer; const Colors: TIntegerArray; const XS, YS, XE, YE: Integer)

You are giving it the following:
FindColors(out TPA: TPointArray; const Color: Integer; const XS, YS, XE, YE: Integer)

I did this, It does compile now, but it wont find the window of the game.



program Diamond_Minder;

//var
// T: Boolean;

const
Mode = 1; //Can be set to 1 or 2. Im not sure what is fastes :P

procedure WaitRR(MinWait, MaxWait: Integer);
begin
Wait(MinWait + Random(MaxWait - MinWait));
end;

function CheckForGame: Boolean;
var
TPA: TIntArray;
x, y : Longint;
begin
FindColors(x, y, TPA, 0, 0, 437, 318);
//FindColors(TPA, 16777215, 0, 0, 437, 318);
If length(TPA) < 500 then begin
result := false;
end else begin
result := true;
end;
end;

procedure WaitForCleared;
var
TPA: TIntArray;
BX, NX: Integer;
x, y : Longint;
begin
Wait(100);
Repeat
FindColors(x,y, TPA, 0, 0, 437, 318);
//FindColors(TPA, 16777215, 0, 0, 437, 318)
BX := Length(TPA);
WaitRR(50, 75);
FindColors(x,y,TPA, 0, 0, 437, 318);
//FindColors(TPA, 16777215, 0, 0, 437, 318)
NX := Length(TPA);
Until(BX = NX);
end;

procedure StartNewGame;
var
TPA, TPA2: TIntArray;
x, y, LX, LY: Integer;

begin
WaitRR(2000, 2100);
WaitForCleared;
FindColors(x,y,TPA, 181, 349, 266, 364);
//FindColors(TPA, 2986564, 181, 349, 266, 364)
MouseInBox(Box(181, 349, 266, 364));
//MouseBox(181, 349, 266, 364);
FindColors(x,y,TPA2, 181, 349, 266, 364);
//FindColors(TPA2, 2986564, 181, 349, 266, 364)
WaitRR(10, 20);
LX := Length(TPA);
LY := Length(TPA2);
if LX > LY then begin
Writeln('Started a new game');
end else begin
writeln('Could not find the start button stopping the script');
TerminateScript;
end;
GetMousePos(x, y);
ClickMouse(x, y, True);
MoveMouseBox(Box(140 + Random(300), 0 + random(320), 0, 0));
//MoveWindMouse(140 + Random(300), 0 + random(320), 0, 0);
While InRange(LX, 100, 500) do begin
//FindColors(TPA, 16777215, 214, 57, 485, 328);
FindColors(x, y, TPA, 214, 57, 485, 328);
LX := Length(TPA);
Writeln(Lx)
end;
Writeln(1);
WaitRR(850, 950);
end;

//Default: GetBoxBounds(154, 18, 185, 49, 34, 34, 1, 1)

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Description: Turn a big box in to small boxes and return the given box as a TBox

xs, ys, xe, ye: The cordinates of the big box.
CordsPerBoxX, PixelsPerBoxY: Number of coordinates between the small boxes.
BoxX, BoxY: The returned boxes. example: (1, 1)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

function GetBoxBoundsEx (xs, ys, xe, ye, CordsPerBoxX, CordsPerBoxY, BoxX, BoxY: Integer): TBox;
begin
result := IntToBox(xs + (CordsPerBoxX * (BoxX - 1)), ys + (CordsPerBoxY * (BoxY - 1)), xe + (CordsPerBoxX * (BoxX - 1)), ye + (CordsPerBoxY * (BoxY - 1)));
end;

function GetBoxBounds (BoxX, BoxY: Integer): TBox;
begin
result := IntToBox(214 + (34 * (BoxX - 1)), 57 + (34 * (BoxY - 1)), 247 + (34 * (BoxX - 1)), 90 + (34 * (BoxY - 1)));
end;

procedure GetCoords (var xs, ys, xe, ye: Integer; BoxX, BoxY: Integer);
begin
xs := GetBoxBounds(BoxX, BoxY).x1;
ys := GetBoxBounds(BoxX, BoxY).y1;
xe := GetBoxBounds(BoxX, BoxY).x2;
ye := GetBoxBounds(BoxX, BoxY).y2;
end;

function CompareColors(i, e, i2, e2, i3, e3, i4, e4, ColorA: Integer; Var Colors: TIntegerArray; var TBFrom: TPoint; var TBTo: TBox): Boolean;
var
xs, ys, xe, ye, x, y: Integer;
begin
//1st (i)
GetCoords(xs, ys, xe, ye, i, e);
if FindColorTol(x, y, Colors[ColorA], xs, ys, xe, ye, 2) then begin
//if FindColorTolerance(x, y, Colors[ColorA], xs, ys, xe, ye, 2) then begin
//2nd (i2)
GetCoords(xs, ys, xe, ye, i + i2, e + e2);
if FindColorTol(x, y, Colors[ColorA], xs, ys, xe, ye, 2) then begin
//if FindColorTolerance(x, y, Colors[ColorA], xs, ys, xe, ye, 2) then begin
//4rd (i3)
GetCoords(xs, ys, xe, ye, i + i3, e + e3);
if FindColorTol(x, y, Colors[ColorA], xs, ys, xe, ye, 2) then begin
//if FindColorTolerance(x, y, Colors[ColorA], xs, ys, xe, ye, 2) then begin
TBFrom := Point(x, y);
//3rd (i4)
GetCoords(xs, ys, xe, ye, i + i4, e + e4);
TBTo := Box(xs, ys, xe, ye);
Result := True;
exit;
end;
end;
end;
end;

function GetOptions (Colors: TIntegerArray; var TBFrom: TPoint; var TBTo: TBox): Boolean;
var
i, e, c, H: Integer;
begin
H := High(Colors);
for c := 0 to H do begin //Colors
for e := 1 to 8 do begin //Y row
for i := 1 to 8 do begin //X row
//Pattern 1
if CompareColors(i, e, 1, 0, 3, 0, 2, 0, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 1');
exit;
//Pattern 2
end else if CompareColors(i, e, -1, 0, -3, 0, -2, 0, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 2');
exit;
//Pattern 3
end else if CompareColors(i, e, 0, -1, -1, -2, 0, -2, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 3');
exit;
//Pattern 4
end else if CompareColors(i, e, 0, -1, 1, -2, 0, -2, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 4');
exit;
//Pattern 5
end else if CompareColors(i, e, 0, -2, 1, -1, 0, -1, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 5');
exit;
//Pattern 6
end else if CompareColors(i, e, 0, 1, 1, 2, 0, 2, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 6');
exit;
//Pattern 7
end else if CompareColors(i, e, 0, 1, -1, 2, 0, 2, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 7');
exit;
//Pattern 8
end else if CompareColors(i, e, 1, 0, 2, -1, 2, 0, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 8');
exit;
//Pattern 9
end else if CompareColors(i, e, 1, 0, 2, 1, 2, 0, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 9');
exit;
//Pattern 10
end else if CompareColors(i, e, 2, 0, 1, 1, 1, 0, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 10');
exit;
//Pattern 11
end else if CompareColors(i, e, 2, 0, 1, -1, 1, 0, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 11');
exit;
//Pattern 12
end else if CompareColors(i, e, 0, 1, 0, 3, 0, 2, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 12');
exit;
//Pattern 13
end else if CompareColors(i, e, -1, 0, -2, -1, -2, 0, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 13');
exit;
//Pattern 14
end else if CompareColors(i, e, 0, -1, 0, -3, 0, -2, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 14');
exit;
//Pattern 15
end else if CompareColors(i, e, 0, 2, -1, 1, 0, 1, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 15');
exit;
end else if CompareColors(i, e, -1, 0, -2, 1, -2, 0, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 16');
exit;
end;
end;
end;
end;
writeln('No more options. Starting a new game');
WaitForCleared;
StartNewGame;
end;

procedure ClickBoxes;
var
x, y: Integer;
TBFrom: TPoint;
TBTo: TBox;
begin
if Mode = 1 then WaitForCleared;
// | Grey | | Red | |Purple| |Green| | Blue | | Teal| |Yellow|
if GetOptions([5918276, 6119398, 5450823, 4806974, 6703944, 8485181, 5171947, 8089653, 4538462], TBFrom, TBTo) then begin
MoveMouse(TBFrom.X, TBFrom.Y);
if Mode = 2 then WaitForCleared;
ClickMouse(TBFrom.X, TBFrom.Y, True);
MouseInBox(Box(TBTo.x1, TBTo.y1, TBTo.x2, TBTo.y2));
//MouseBox(TBTo.x1, TBTo.y1, TBTo.x2, TBTo.y2);
GetMousePos(x, y);
ClickMouse(x, y, True);
end;
end;

begin
ClearDebug;
Writeln('Welcome to sjespers Diamond Minder');
if CheckForGame = false then begin
writeln('Did not detect the game. Remember to drag the target to the game. If its not working then try to refresh the game');
TerminateScript;
end else begin
writeln('Found the game. Starting to make you some tokens');
end;
repeat
ClickBoxes;
until(false)
end.

Clarity
12-01-2015, 12:06 AM
I did this, It does compile now, but it wont find the window of the game.

writeln('Did not detect the game. Remember to drag the target to the game. If its not working then try to refresh the game');

Have you selected the game as Simba/Scar's target?

Laquisha
12-01-2015, 12:17 AM
You never told it what color to look for. Mr Slacky told you how to fix it


function CheckForGame: Boolean;
var
TPA: TPointArray;
begin
FindColorEx(TPA, 16777215, 0, 0, 437, 318);
Result := (Length(TPA) < 500);
end;

jonas9513
12-01-2015, 12:34 PM
Thank you very much for helping me!

Now I've came a long way!
Now it is detecting the game, also its finding the patterns in the game.
But it does not move them...
I guess it has something with ClickMouse(x, y, true)? But I'm not sure.



program Diamond_Minder;

//var
// T: Boolean;

const
Mode = 1; //Can be set to 1 or 2. Im not sure what is fastes :P

procedure WaitRR(MinWait, MaxWait: Integer);
begin
Wait(MinWait + Random(MaxWait - MinWait));
end;

function CheckForGame: Boolean;
var
TPA: TPointArray;
begin
FindColorEx(TPA, 16777215, 0, 0, 437, 318);
if (Length(TPA) < 500) then begin
result := false;
end else begin
result := true;
end;
end;

procedure WaitForCleared;
var
TPA: TPointArray;
BX, NX: Integer;
// x, y : Longint;
begin
Wait(100);
Repeat
FindColorEx(TPA, 16777215, 0, 0, 437, 318);
//FindColors(TPA, 16777215, 0, 0, 437, 318)
BX := Length(TPA);
WaitRR(50, 75);
FindColorEx(TPA, 16777215, 0, 0, 437, 318);
//FindColors(TPA, 16777215, 0, 0, 437, 318)
NX := Length(TPA);
Until(BX = NX);
end;

procedure StartNewGame;
var
TPA, TPA2: TPointArray;
x, y, LX, LY: Integer;

begin
WaitRR(2000, 2100);
WaitForCleared;
FindColorEx(TPA, 2986564, 181, 349, 266, 364);
MouseInBox(Box(181, 349, 266, 364));
//MouseBox(181, 349, 266, 364);
FindColorEx(TPA2, 2986564, 181, 349, 266, 364);
WaitRR(10, 20);
LX := Length(TPA);
LY := Length(TPA2);
if LX > LY then begin
Writeln('Started a new game');
end else begin
writeln('Could not find the start button stopping the script');
TerminateScript;
end;
GetMousePos(x, y);
ClickMouse(x, y, True);
MoveMouseBox(Box(140 + Random(300), 0 + random(320), 0, 0));
//MoveWindMouse(140 + Random(300), 0 + random(320), 0, 0);
While InRange(LX, 100, 500) do begin
FindColorEx(TPA, 16777215, 214, 57, 485, 328);
LX := Length(TPA);
Writeln(Lx)
end;
Writeln(1);
WaitRR(850, 950);
end;

//Default: GetBoxBounds(154, 18, 185, 49, 34, 34, 1, 1)

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Description: Turn a big box in to small boxes and return the given box as a TBox

xs, ys, xe, ye: The cordinates of the big box.
CordsPerBoxX, PixelsPerBoxY: Number of coordinates between the small boxes.
BoxX, BoxY: The returned boxes. example: (1, 1)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

function GetBoxBoundsEx (xs, ys, xe, ye, CordsPerBoxX, CordsPerBoxY, BoxX, BoxY: Integer): TBox;
begin
result := IntToBox(xs + (CordsPerBoxX * (BoxX - 1)), ys + (CordsPerBoxY * (BoxY - 1)), xe + (CordsPerBoxX * (BoxX - 1)), ye + (CordsPerBoxY * (BoxY - 1)));
end;

function GetBoxBounds (BoxX, BoxY: Integer): TBox;
begin
result := IntToBox(214 + (34 * (BoxX - 1)), 57 + (34 * (BoxY - 1)), 247 + (34 * (BoxX - 1)), 90 + (34 * (BoxY - 1)));
end;

procedure GetCoords (var xs, ys, xe, ye: Integer; BoxX, BoxY: Integer);
begin
xs := GetBoxBounds(BoxX, BoxY).x1;
ys := GetBoxBounds(BoxX, BoxY).y1;
xe := GetBoxBounds(BoxX, BoxY).x2;
ye := GetBoxBounds(BoxX, BoxY).y2;
end;

function CompareColors(i, e, i2, e2, i3, e3, i4, e4, ColorA: Integer; Var Colors: TIntegerArray; var TBFrom: TPoint; var TBTo: TBox): Boolean;
var
xs, ys, xe, ye, x, y: Integer;
begin
//1st (i)
GetCoords(xs, ys, xe, ye, i, e);
if FindColorTol(x, y, Colors[ColorA], xs, ys, xe, ye, 2) then begin
//if FindColorTolerance(x, y, Colors[ColorA], xs, ys, xe, ye, 2) then begin
//2nd (i2)
GetCoords(xs, ys, xe, ye, i + i2, e + e2);
if FindColorTol(x, y, Colors[ColorA], xs, ys, xe, ye, 2) then begin
//if FindColorTolerance(x, y, Colors[ColorA], xs, ys, xe, ye, 2) then begin
//4rd (i3)
GetCoords(xs, ys, xe, ye, i + i3, e + e3);
if FindColorTol(x, y, Colors[ColorA], xs, ys, xe, ye, 2) then begin
//if FindColorTolerance(x, y, Colors[ColorA], xs, ys, xe, ye, 2) then begin
TBFrom := Point(x, y);
//3rd (i4)
GetCoords(xs, ys, xe, ye, i + i4, e + e4);
TBTo := Box(xs, ys, xe, ye);
Result := True;
exit;
end;
end;
end;
end;

function GetOptions (Colors: TIntegerArray; var TBFrom: TPoint; var TBTo: TBox): Boolean;
var
i, e, c, H: Integer;
begin
H := High(Colors);
for c := 0 to H do begin //Colors
for e := 1 to 8 do begin //Y row
for i := 1 to 8 do begin //X row
//Pattern 1
if CompareColors(i, e, 1, 0, 3, 0, 2, 0, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 1');
exit;
//Pattern 2
end else if CompareColors(i, e, -1, 0, -3, 0, -2, 0, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 2');
exit;
//Pattern 3
end else if CompareColors(i, e, 0, -1, -1, -2, 0, -2, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 3');
exit;
//Pattern 4
end else if CompareColors(i, e, 0, -1, 1, -2, 0, -2, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 4');
exit;
//Pattern 5
end else if CompareColors(i, e, 0, -2, 1, -1, 0, -1, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 5');
exit;
//Pattern 6
end else if CompareColors(i, e, 0, 1, 1, 2, 0, 2, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 6');
exit;
//Pattern 7
end else if CompareColors(i, e, 0, 1, -1, 2, 0, 2, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 7');
exit;
//Pattern 8
end else if CompareColors(i, e, 1, 0, 2, -1, 2, 0, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 8');
exit;
//Pattern 9
end else if CompareColors(i, e, 1, 0, 2, 1, 2, 0, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 9');
exit;
//Pattern 10
end else if CompareColors(i, e, 2, 0, 1, 1, 1, 0, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 10');
exit;
//Pattern 11
end else if CompareColors(i, e, 2, 0, 1, -1, 1, 0, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 11');
exit;
//Pattern 12
end else if CompareColors(i, e, 0, 1, 0, 3, 0, 2, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 12');
exit;
//Pattern 13
end else if CompareColors(i, e, -1, 0, -2, -1, -2, 0, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 13');
exit;
//Pattern 14
end else if CompareColors(i, e, 0, -1, 0, -3, 0, -2, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 14');
exit;
//Pattern 15
end else if CompareColors(i, e, 0, 2, -1, 1, 0, 1, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 15');
exit;
end else if CompareColors(i, e, -1, 0, -2, 1, -2, 0, C, Colors, TBFrom, TBTo) then begin
Result := True;
Writeln('Clicked Pattern 16');
exit;
end;
end;
end;
end;
writeln('No more options. Starting a new game');
WaitForCleared;
StartNewGame;
end;

procedure ClickBoxes;
var
x, y: Integer;
TBFrom: TPoint;
TBTo: TBox;
begin
if Mode = 1 then WaitForCleared;
// | Grey | | Red | |Purple| |Green| | Blue | | Teal| |Yellow|
if GetOptions([5918276, 6119398, 5450823, 4806974, 6703944, 8485181, 5171947, 8089653, 4538462], TBFrom, TBTo) then begin
MoveMouse(TBFrom.X, TBFrom.Y);
if Mode = 2 then WaitForCleared;
ClickMouse(TBFrom.X, TBFrom.Y, True);
MouseInBox(Box(TBTo.x1, TBTo.y1, TBTo.x2, TBTo.y2));
//MouseBox(TBTo.x1, TBTo.y1, TBTo.x2, TBTo.y2);
GetMousePos(x, y);
ClickMouse(x, y, True);
end;
end;

begin
ClearDebug;
Writeln('Welcome to sjespers Diamond Minder');
if CheckForGame = false then begin
writeln('Did not detect the game. Remember to drag the target to the game. If its not working then try to refresh the game');
TerminateScript;
end else begin
writeln('Found the game. Starting to make you some tokens');
end;
repeat
ClickBoxes;
until(false)
end.