PDA

View Full Version : [TUT]Brief intro on Results



Smarter Child
02-04-2010, 02:23 AM
Brief Intro On Results

In Scar you are going to need to know how to use results.

Have you ever seen in a script, something like this:

Run the following script-

Program New;

Function Results: boolean;
var
x: integer;
begin
x := 5 //declares the x variable to the number 5
if x > 2 then //if x is greater than 2 it continues
begin
Writeln('YAY');
Result := true; //since x was greater than 2, it resulted as true=yes
end;
end;

begin
if Results = true then //if the Result was true it will cleardebug etc.
ClearDebug;
end.

Now that is a basic example of using a result. But, you don't have to type in if Results = true then blah blah

You can simply write if Results then blah blah

It automatically checks if the result was true, so if in the Function Results, it resulted false, it would not clear the debug etc.

Now, let's try using a false result too:

Run the following script-

Program New;

Function Results: boolean;
var
x: integer;
begin
x := 5 //declares the x variable to the number 5
if x = 2 then //if x equals 5 then it does the following
begin
Writeln('YAY');
Result := true; //since x was greater than 2, it resulted as true=yes
end;
if x < 10 then //if x is less than 10 itdoes the following
begin
Writeln('aww, x was less than 10..');
Result := false;
end;
end;

begin
if Results then //if the Result was true it will cleardebug etc.
begin
ClearDebug;
Writeln('......');
end;
end.

As you notice, when you run this script the debug box will not be cleared and it will not write in : ........

but if you change if Results then to if not Results then it will clear the debug and write in : ...........

Isn't that neat?

If you start writing runescape scripts it will help a lot, for example:

program New;

Function FindsColor:boolean;
var
color: integer;
begin
color := 6914286; //declares color
if FindColor(x, y, Color, MSX1, MSY1, MSX2, MSY2)then //if scar finds the color on the Mainscreen of runescape then it does the rest...
begin
Writeln('found the color');
Result := true;
end;
end;

begin
if FindsColor then
DoTheRestOfTheRunescapeScript; //:p
end.

Have you ever notice that some functions say: Function WTF: integer;

That means the functions results as a numerical value aka integer.

This can be helpful in many situations when you are scripting for runescape:

program New;

Function FindsColor: integer; //notice: it results as an integer
var
color: integer;
begin
color := 6914286; //declares color
if FindColor(x, y, Color, MSX1, MSY1, MSX2, MSY2)then //if scar finds the color on the Mainscreen of runescape then it does the rest...
begin
Writeln('found the color');
Result := color;
end;
end;

begin
if FindsColor = 6914286 then //if the color was the same color it will continue.
DoTheRestOfTheScript; //:p
end.

Now you probably notice that was really precise. You probably won't be able to get the exact colors on runescape, so some people do if FindsColor > 1. That just means some form of color was found since 0 = black.

Without functions resulting as integers autocoloring wouldn't be as easy as it is.

Notice in RadialWalk, the color sometimes you use:

RadialWalk(FindVarrockRoadColor, blah.....

That's because the function in AutoColor.scar called FindVarrockRoadColor results as an integer[the actual colour]. The Result on an integer can look like:

Result := FinalColor; //finalcolor is declared as an integer in the script

I know this tutorial is a little brief and it might be missing some information, but I hope you learn something from this. :)

~~ END ~~

- Smarter Child

Sex
02-04-2010, 02:25 AM
A tutorial really isn't needed for this as it is basically a tutorial on functions which already exists.
The result variable is simply what the function returns..

Mr. Doctor
02-04-2010, 02:26 AM
Definitely needed, I know someone who doesn't understand results.

E : Ninjad, ROFL.

Smarter Child
02-04-2010, 02:27 AM
A tutorial really isn't needed for this as it is basically a tutorial on functions which already exists.
The result variable is simply what the function returns..


Definitely needed, I know someone who doesn't understand results.

*cough*

Anyways, whether it is not needed or not, it still is knowledge worth sharing ;)

chitin
02-04-2010, 02:27 AM
nice little tut. to be honest i thought it was something completly different. but it did show me something i was interested in. soo thanks anyway. but u should make a [TUT] in the thread name so ppl know lol. otherwise teh name suggests other thigns..

Smarter Child
02-04-2010, 02:33 AM
Thanks chitin, I'll do that. Wow you guys are epic, I think everybody just sits on the iSpy part of SRL. :p

noidea
02-04-2010, 02:35 AM
Nice!

Frement
02-04-2010, 02:39 AM
Maybe mention you can return any type you want? From TPoint to Integer and so on.

i luffs yeww
02-04-2010, 03:27 AM
I think it's simple, but nice to remind new scripters that things such as


function wat: Boolean;
var
x, y: Integer;
begin
Result := FindColor(x, y, 65536, 0, 0, 1, 1);
Writeln(BoolToStr(Result));
end;

begin
if wat then
Writeln('Found the color.');
end.


(Showing that you can do Result := (Any function here);, because it's more neat, and looks sexier than if wat then Result := True;.. you know? :p)

NCDS
02-04-2010, 04:05 AM
I think it's simple, but nice to remind new scripters that things such as


function wat: Boolean;
var
x, y: Integer;
begin
Result := FindColor(x, y, 65536, 0, 0, 1, 1);
Writeln(BoolToStr(Result));
end;

begin
if wat then
Writeln('Found the color.');
end.


(Showing that you can do Result := (Any function here);, because it's more neat, and looks sexier than if wat then Result := True;.. you know? :p)

Not any function. The function you are setting to Result would have to return the same type as the function you are "resulting". If that makes sense at all.

Example:

function this: Boolean;
begin
Result := (ThisFunctionReturnsAnInteger);
end;

That wouldn't work, as ThisFunctionReturnsAnInteger, would need to return a Boolean.

i luffs yeww
02-04-2010, 04:23 AM
Not any function. The function you are setting to Result would have to return the same type as the function you are "resulting". If that makes sense at all.

Example:

function this: Boolean;
begin
Result := (ThisFunctionReturnsAnInteger);
end;

That wouldn't work, as ThisFunctionReturnsAnInteger, would need to return a Boolean.

Yup. But I meant like.. if they match.. :p Like any function, as long as you convert it, or the type the function returns matches.

L2Program
02-27-2010, 04:17 PM
Thanks for this, learnt something.