SRL Archive - OSR Help

Basic Script help


Rizowski

2010-05-22 15:59:42

Hey!

I have read the beginner guide a couple times now and I have tried to put my knowledge to use, I don't believe I am doing it right though.

Here is the script I have:

Program colorfinder;

{to find yellow balloon text button on pdf program
Begin at loc 22,556, Use Spiral colorfind until finding color for button.}
function FindColor1: Integer;

begin
FindColorCircle: 28460473;
end;

Procedure WriteLn1;
begin //once found color write in found color
if FindColor1 := True
Then WriteLn('I have found what you were looking for :)')
TerminateScript;
end;

begin
FindColor1
WriteLn1
end.

It is supposed to be very simple, find the yellow color balloon button on a open pdf file. (I am not using bitmaps for now.) I want it to start at a certain point and go out. After it finds the color it types in the Debug box the message above.


I have tried compiling this in Luna, as it has a bit more friendly tips and easier to read begin and end functions, as they are linked together. I know it does not work as there are some things missing, but I am not sure what to put or how?

Any help would be great, I have said in other posts that I have been wanting to learn as much as I can. So by all means, if it is brutal, bring it. :P

NCDS

2010-05-22 16:14:26


function FindTheYellowBalloon: Boolean;
var
Arr: TPointArray;
begin
FindColorsSpiralTolerance(x, y, Arr, ColorHere, x1, y1, x2, y2, ToleranceHere);
if Length(Arr) > 1 then
begin
Result := True;
Writeln('mssage here');
end;
end;
'x' and 'y' specify where you want to start searching from.
'Arr' is just the array that the function will store the points where it finds the color.
'x1' and 'y1' represent the top right corner of the box you want to search in.
'x2' and 'y2' represent the bottom right corner of the box you wish to search.

When you open up scar, press f1 and it will bring up asort of "guide" on the functions and very briefly explain how to use them.

Rizowski

2010-05-22 16:28:46

So the Arr does not need to be filled in with anything or is does it need to be modified?

NCDS

2010-05-22 16:37:57

Nope you would leave 'Arr' just as it is.

Rizowski

2010-05-22 16:52:54

Ok so I put in the required info. Executed the script and only received this:

Successfully compiled (70 ms)
Successfully executed

What would cause it not to put in the write in command?

NCDS

2010-05-22 17:09:52

if it didn't find at least two occurrence's of the color you searched for.

Change:

if Length(Arr) > 1 then
begin
Result := True;
Writeln('mssage here');
end;
to:

if Length(Arr) > 1 then
begin
Result := True;
Writeln('mssage here');
end
else
Writeln('failed to find color');

Rizowski

2010-05-22 17:31:02

Cool! haha Thanks

Dgby714

2010-05-22 21:28:59

You could also make it return a TPoint so you can call it then click =)

Rizowski

2010-05-24 13:53:00

From: Dgby714
You could also make it return a TPoint so you can call it then click =)


Tpoint? Please Explain?

Wanted

2010-05-24 13:56:42

From: NCDS

'x1' and 'y1' represent the top right corner of the box you want to search in.


You mean top left corner?

Dgby714

2010-05-24 15:14:29

From: moae3
Tpoint? Please Explain?


So Basically a TPoint is

type
TPoint = record
x: integer;
y: integer;
end;

So you can store x, y coordinates, Like where you want to click =)

function FindTheYellowBalloon: TPoint;  //<-- Result is now a TPoint
var
Arr: TPointArray; //Arr is a array of TPoint
begin
Result := Point(-1, -1); //We will make Result = -1, -1 (x, y) Just incase You dont find the colors

FindColorsSpiralTolerance(x, y, Arr, ColorHere, x1, y1, x2, y2, ToleranceHere);

if Length(Arr) > 1 then
begin
//Now here you can loop thru Arr and find the best match but were just gonna use Arr[0]
Result := Arr[0]; //Result := the first TPoint in Arr
Writeln('mssage here');
end;
end;

Rizowski

2010-05-24 15:51:42

From: IceFire908
You mean top left corner?


It still worked?



From: Dgby714
So Basically a TPoint is

type
TPoint = record
x: integer;
y: integer;
end;

So you can store x, y coordinates, Like where you want to click =)

function FindTheYellowBalloon: TPoint;  //<-- Result is now a TPoint
var
Arr: TPointArray; //Arr is a array of TPoint
begin
Result := Point(-1, -1); //We will make Result = -1, -1 (x, y) Just incase You dont find the colors

FindColorsSpiralTolerance(x, y, Arr, ColorHere, x1, y1, x2, y2, ToleranceHere);

if Length(Arr) > 1 then
begin
//Now here you can loop thru Arr and find the best match but were just gonna use Arr[0]
Result := Arr[0]; //Result := the first TPoint in Arr
Writeln('mssage here');
end;
end;



So I tried to run the script as is after inserting needed info. It came up with:

Line 1: [Error] (1:1): Unexpected end of file in script

I looked at the way it was written previously and noticed it has:

  function FindTheYellowBalloon: Boolean;

So I replaced: TPoint with TPointArray? It seemed to work other than it stated this error
Line 6: [Error] (6:23): Type mismatch in script
? I tried to put in a point and some other things to see if i could correct it. But haha idk what is wrong?

Dgby714

2010-05-24 19:10:31

Weird

This compiles for me perfecty fine >.<
program new;

const
ColorHere = 0;
ToleranceHere = 0;
x1 = 0;
x2 = 0;
y1 = 0;
y2 = 0;

function FindTheYellowBalloon: TPoint; //<-- Result is now a TPoint
var
x, y: integer;
Arr: TPointArray; //Arr is a array of TPoint
begin
Result := Point(-1, -1); //We will make Result = -1, -1 (x, y) Just incase You dont find the colors

FindColorsSpiralTolerance(x, y, Arr, ColorHere, x1, y1, x2, y2, ToleranceHere);

if Length(Arr) > 1 then
begin
//Now here you can loop thru Arr and find the best match but were just gonna use Arr[0]
Result := Arr[0]; //Result := the first TPoint in Arr
Writeln('mssage here');
end;
end;

begin
end.

mrpickle

2010-05-24 20:32:04

Still keeping it simple and to your original post. I learn by comparing code, maybe you do as well :). Simple, and straight forward. Included two code. Your way, and a shorter way.


// Your Code modified
Program colorfinder;

{to find yellow balloon text button on pdf program
Begin at loc 22,556, Use Spiral colorfind until finding color for button.}

var x,y:integer;


function FindColor1: Boolean; // Boolean will return either true or false.

begin // the dimensions to look in (0,0 is top left)
if(FindColor(x,y,28460473, 0,0,999,999))then
begin
result := true; // we use := to assign values.
end else // otherwise... must contain begin statement. Also represents end of that begin
begin
result := false;
end;
end;

Procedure WriteLn1;
begin //once found color write in found color
if (FindColor1 = True) then // we don't use := here because it is comparing two variables.
begin
WriteLn('I have found what you were looking for :)')
TerminateScript;
end else
begin
writeln('Nope, not found');
end;
end;

begin
FindColor1
WriteLn1
end.


//How I would have done it
Program colorfinder;

var x,y:integer;

begin
If(FindColor(x,y,28460473,0,0,999,999))then
begin
Writeln('I have found what you were looking for :)');
end else
begin
Writeln('Nope, not found!');
end;
end.