Results 1 to 12 of 12

Thread: [TUT]Brief intro on Results

  1. #1
    Join Date
    Jul 2008
    Location
    Canada
    Posts
    1,612
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default [TUT]Brief intro on Results

    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-
    SCAR Code:
    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-

    SCAR Code:
    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
    SCAR Code:
    if Results then
    to
    SCAR Code:
    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:
    SCAR Code:
    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:
    SCAR Code:
    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:

    SCAR Code:
    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:

    SCAR Code:
    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

  2. #2
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    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..
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  3. #3
    Join Date
    Jan 2007
    Posts
    834
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

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

    E : Ninjad, ROFL.

  4. #4
    Join Date
    Jul 2008
    Location
    Canada
    Posts
    1,612
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Sex View Post
    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..
    Quote Originally Posted by Junkj View Post
    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

  5. #5
    Join Date
    Oct 2007
    Posts
    678
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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..

  6. #6
    Join Date
    Jul 2008
    Location
    Canada
    Posts
    1,612
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks chitin, I'll do that. Wow you guys are epic, I think everybody just sits on the iSpy part of SRL.

  7. #7
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Nice!
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

  8. #8
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Maybe mention you can return any type you want? From TPoint to Integer and so on.
    There used to be something meaningful here.

  9. #9
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    I think it's simple, but nice to remind new scripters that things such as

    SCAR Code:
    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? )

  10. #10
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Quote Originally Posted by i luffs yeww View Post
    I think it's simple, but nice to remind new scripters that things such as

    SCAR Code:
    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? )
    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:
    SCAR Code:
    function this: Boolean;
    begin
      Result := (ThisFunctionReturnsAnInteger);
    end;
    That wouldn't work, as ThisFunctionReturnsAnInteger, would need to return a Boolean.
    Last edited by NCDS; 02-04-2010 at 04:07 AM.

  11. #11
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    Quote Originally Posted by NCDS View Post
    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:
    SCAR Code:
    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.. Like any function, as long as you convert it, or the type the function returns matches.

  12. #12
    Join Date
    Feb 2010
    Posts
    46
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks for this, learnt something.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •