Results 1 to 9 of 9

Thread: Help me with my first script please.

  1. #1
    Join Date
    May 2008
    Posts
    34
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Help me with my first script please.

    My dad is trying to teach me SCAR and has experience with Pascal and other programing languages. This is our first script:
    program New;

    function factorial (n : integer): integer;
    var i, res: integer;
    begin
    res:=1;
    i:=1;
    while (i<=n) do
    begin
    res:=res*i;
    i:=i+1;
    end;
    factorial:=res;
    end;

    begin
    Writeln(IntToStr(factorial(10)));
    end.
    ___________________
    We get the following error:
    Line 13: [Error] (13:10): Invalid number of parameters in script C:\Users\Grisha\Desktop\first script.scar
    Thank you for your help!

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

    Default

    Can you enter the script in SCAR tags please? IT makes it a whole lot easier to read. Thanks. (SCAR tags is when you are posting, hit the little SCAR icon in the options for smileys ect, anD paste the script between the [SCAR][`/SCAR].)


    noidea
    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

  3. #3
    Join Date
    Nov 2007
    Posts
    437
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    another type of statement used in SCAR that your dad probably does not know about is for-to-do statements

    SCAR Code:
    for i := 1 to n do
    begin

    end;

    They are much easier and save you from having to doing i := i + 1; it does it itself. Also if you want to do res := res + 1 you can also use the function Inc() built into scar. Note: there is also Dec which is the equivalent of i-- or i := i - 1;

    There is also a built in function for this called Fract() - i think they misspelled factorial as fractorial hehe.

    to see all of the functions and procedures built into SCAR hit f1 while using the program.

  4. #4
    Join Date
    Jul 2008
    Posts
    21
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You need to use this:

    SCAR Code:
    Result := res;

    to return the result in SCAR. If you create a function that returns a value, the Result parameter is added automatically as the output parameter. So instead of using 'FunctionName := OutputValue' (as is common in many programming languages), use 'Result := OutputValue'.

    So your script should be:

    SCAR Code:
    program New;

    function Factorial (n : integer): integer;
    var i, res: integer;
    begin
      res := 1;
      i := 1;

      while (i<=n) do
      begin
        res := res * i;
        i := i + 1;
      end;
     
      Result := res;
    end;

    begin
      WriteLn(IntToStr(Factorial(10)));
    end.

    Cheers,
    Stash

  5. #5
    Join Date
    May 2008
    Posts
    34
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thank you so much for your help!

  6. #6
    Join Date
    Jul 2008
    Posts
    21
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You're welcome

    Stash

  7. #7
    Join Date
    Jul 2008
    Location
    California
    Posts
    255
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    You can use that function or use the function that is already in Scar:

    SCAR Code:
    function Fract(number: Int64): Int64;
    //Returns the fractorial (!) of number.
    I just tested it and this function works perfectly :P

    So really all you'd need to do is:
    SCAR Code:
    program New;
    begin
    WriteLn(IntToStr(Fract(5{or whatever number you want})));
    end;
    Unfortunately, no active scripts atm.

  8. #8
    Join Date
    Jul 2007
    Location
    Ottawa, Canada
    Posts
    930
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    yea, or he could write his own so he can learn things. -.- gravedigger
    ~ Metagen

  9. #9
    Join Date
    Mar 2008
    Location
    The Netherlands
    Posts
    1,395
    Mentioned
    1 Post(s)
    Quoted
    1 Post(s)

    Default

    Metagen, I have to agree, but hey, 3 weeks isn't really bad?


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
  •