Scar Tutorial: Procedures

Discussion in 'Code Snippets and Tutorials' started by Billy, Mar 31, 2007.

  1. Billy

    Billy Level IV

    Joined:
    Feb 21, 2007
    Messages:
    1,856
    Likes Received:
    39

    Procedures





    What is a Procedure?


    A procedure is a way to shorten repetitive scripts by making you not need to write every step when you want scar to do something. for example if you wanted to make a script that waited, clicked then displayed a message, it would look like this.
    Code (Text):
    1. program New;
    2. begiwait(5000);
    3. clickmouse(5,5, true);
    4. writeln('clicked');
    5. end.
    but if you wanted it to repeat that 50 times, you would have a very long and confusing script. instead of doing that, you would use procedures.


    How do I make a procedure?


    To make a procedure you need a code like this
    Code (Text):
    1. program New;
    2. Procedure click;
    3. begin
    4. wait(5000);
    5. clickmouse(5,5, true);
    6. writeln('clicked');
    7. end;
    8. begin
    9. click;
    10. end.
    "procedure tells scar that you are going to make a procedure. then you put the name. the name can only be one word, or else scar will give you an error. then you write what you want the procedure to do. in this case, scar waits 5 seconds, clicks the mouse, and displays a message. the "end;" tells scar that you are done with your procedure. then you put the name of your procedure in the script and scar runs the procedure.





    What are some advantages of procedures?


    A procedure is a much "cleaner" code than without them. It reduces all of the clutter in a script. this script,
    Code (Text):
    1. program New;
    2. begin
    3. wait(5000);
    4. clickmouse(5,5, true);
    5. writeln('clicked');
    6. wait(5000);
    7. clickmouse(5,5, true);
    8. writeln('clicked');
    9. wait(5000);
    10. clickmouse(5,5, true);
    11. writeln('clicked');
    12. wait(5000);
    13. clickmouse(5,5, true);
    14. writeln('clicked');
    15. wait(5000);
    16. clickmouse(5,5, true);
    17. writeln('clicked');
    18. end.
    19.  
    and this script
    Code (Text):
    1. program New;
    2. Procedure click;
    3. begin
    4. wait(5000);
    5. clickmouse(5,5, true);
    6. writeln('clicked');
    7. end;
    8. begin
    9. click;
    10. click;
    11. click;
    12. click;
    13. click;
    14. end.
    are the same, just that the second one is much neater because it uses procedures. also, if you wanted to change the amount of time you wanted scar to wait, with procedures, you only have to change the value once, while normally, you have to change every time it appears in the script.
     
  2. looneytoon

    looneytoon Level III

    Joined:
    Jan 16, 2007
    Messages:
    568
    Likes Received:
    0
    I thought you already had a guide, anyway nice guide, whya rent you a coder? +Rep
     
  3. Billy

    Billy Level IV

    Joined:
    Feb 21, 2007
    Messages:
    1,856
    Likes Received:
    39
    the other guide is on variables. and once i submit a program or two, i am going to apply to be a programmer.