Results 1 to 7 of 7

Thread: function

  1. #1
    Join Date
    May 2007
    Location
    Some where fun.
    Posts
    2,891
    Mentioned
    1 Post(s)
    Quoted
    5 Post(s)

    Default function

    i have made one auto talker for my self and I'm not going to release cause its noobish and i have made it from a tutorial on this site and it doesn't say what are functions and how to use them?

    can anyone of u tell me how to use them and what they are?

  2. #2
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    functions give back info instead of just doing what u want it to do
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  3. #3
    Join Date
    Feb 2007
    Posts
    3,616
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Well.. The most popular function is a boolean function, which would look like this:

    SCAR Code:
    function CheckChatt: Boolean;

    You'd put where the CheckChatt thing is at whatever you want the name to be, just like a procedure. But the different between a procedure, and a function, is one has a result (With the most popular Boolean function I'm going to show you, its called resulting true or false). Heres an example of how they'd be used:

    SCAR Code:
    program CheckChats
    {.include SRL/SRL.scar}

    function CheckChatt: Boolean;
    begin
      if(InChat('Hi there'))then
        Result := True;
      if(not(InChat('Hi there')))then
        Result := False;
    end;

    procedure Whatever;
    begin
      if(CheckChatt = true) then
        Writeln('Hi there was in the runescape chat box!');
      if(not(CheckChatt = true))then
        Writeln('Hi there was NOT in runescape chat box!');
    end;

    begin //Main loop..
      Whatever;
    end.

    Get it now? It does the CheckChatt function in the Whatever procedure, and if it resulted true, (meaning that Hi there was in chat) It will Writeln 'Hi there was in the runescape chat box!', but if Hi there wasn't in the chat, then it would result false and writeln 'Hi there was NOT in runescape chat box!'

    Get it? Hope I explained that well

    Edit: Dan cardin, you beat me, but you can't beat my descriptivity lol

  4. #4
    Join Date
    Feb 2007
    Location
    USA
    Posts
    667
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You use two types of things to perform events in scar. Procedures and Functions.

    procedure are very simple. They just read through the commands you write and perform them.

    Procedures serve there purpose, but Functions are by far the most useful. Functions will return a value depending on what happens during the course of it's code.

    The only way you can use conditionals is with functions.

    The three most common types are boolean, integer and string functions.
    Examples:
    -FindColor is a boolean function, which returns either true or false, depending whether
    the color is found or not.
    -GetTextAt is a string function. It will return the string at the given coordinates. Since you have been making an autotalker, you should be very familiar with strings.

    -StrToInt is an Integer function which takes in a string and returns it as an integer.


    You can make your own functions like this
    SCAR Code:
    function name(parameters):boolean;{you name the function, and then say what paramaters it takes.
    That is just like making procedues. Functions append this funky ":boolean" thing which specifies what kind of function
     it is. A string function would add ":string"}

    begin
    //what ever actions you want to happen

    result: = //every function returns a result. Depending on what kind of function it is, it will return somehting different. Booleans return true or false, strings return a string.
    end;


    Edit: aww, i hate both of you

  5. #5
    Join Date
    May 2007
    Location
    baltimore, md
    Posts
    836
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    ha i get to explain the params

    SCAR Code:
    function findcolors(color1,color2,color3: integer): boolean;
    var x,y: integer;
    begin
      begin
        if findcolor(x,y,color1) or
           findcolor(x,y,color2) or
           findcolor(x,y,color3) then
        result:=true;
      end else;
      if (not(findcolor(x,y,color1)) and
           (not(findcolor(x,y,color2)) and
           (not(findcolor(x,y,color3)) then
      result:=false;
    end;

    see how in the parameters i labeled color1,color2,and color3 and then later in the script i put them in as well. if this function was filled out
    findcolors(13412,235434,34223) then later in the function where i put color1 it would make that 13412. same with color 2 and 3. i also put integer after them because they are basically variables so you have to define them as integers since they are numbers. then ofcouse boolean makes the function result true or false.

  6. #6
    Join Date
    May 2007
    Location
    Some where fun.
    Posts
    2,891
    Mentioned
    1 Post(s)
    Quoted
    5 Post(s)

    Default

    thanks everyone!

  7. #7
    Join Date
    Feb 2007
    Posts
    3,616
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by jhildy View Post
    ha i get to explain the params

    SCAR Code:
    function findcolors(color1,color2,color3: integer): boolean;
    var x,y: integer;
    begin
      begin
        if findcolor(x,y,color1) or
           findcolor(x,y,color2) or
           findcolor(x,y,color3) then
        result:=true;
      end else;
      if (not(findcolor(x,y,color1)) and
           (not(findcolor(x,y,color2)) and
           (not(findcolor(x,y,color3)) then
      result:=false;
    end;

    see how in the parameters i labeled color1,color2,and color3 and then later in the script i put them in as well. if this function was filled out
    findcolors(13412,235434,34223) then later in the function where i put color1 it would make that 13412. same with color 2 and 3. i also put integer after them because they are basically variables so you have to define them as integers since they are numbers. then ofcouse boolean makes the function result true or false.
    Actually, you can do the exact same thing with a procedure with parameters, it just doesn't result So asking about functions doesn't necessarily mean your asking about parameters because he may have known how to use that with procedures

    And np sport, glad to help

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 02-27-2008, 05:20 PM
  2. Replies: 2
    Last Post: 02-26-2008, 08:26 PM
  3. Any function that does this?
    By shadowpwner in forum OSR Help
    Replies: 2
    Last Post: 08-14-2007, 03:15 AM
  4. [FUNCTION] FindDoorColour: integer; By ZephyrsFury [FUNCTION]
    By ZephyrsFury in forum Research & Development Lounge
    Replies: 10
    Last Post: 07-27-2007, 08:45 AM

Posting Permissions

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