Results 1 to 8 of 8

Thread: return multiple vars in function

  1. #1
    Join Date
    Jul 2006
    Posts
    259
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default return multiple vars in function

    i know in c++ you have to put "&" before the variable but how do you do it in scar
    "your always where you supposed to be"

  2. #2
    Join Date
    Dec 2006
    Location
    utah
    Posts
    1,427
    Mentioned
    2 Post(s)
    Quoted
    7 Post(s)

    Default

    SCAR Code:
    Program New;

    Var
         x, y, x1, y1, x2, y2: Integer;// replace and with ","
     // if thats what you mean...
    begin
    x1 := 0;
    y1 := 0;
    x2 := 713;
    y2 := 515;

    If (FindColor(x, y, 0, x1, y1, x2, y2)) then
    Writeln('found Color');
    end;

  3. #3
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    SCAR Code:
    Function(var Return1: Integer; var Return2: String; var Return3: TPoint): Boolean;

    This would return an integer, a string, a TPoint and a Boolean. Just put var before what you want to be returned.
    Hup Holland Hup!

  4. #4
    Join Date
    Jul 2006
    Posts
    259
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    thanks alot nielsie
    "your always where you supposed to be"

  5. #5
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    I don't understand your post Neilsie...

    You could do something like this, with variants...
    SCAR Code:
    function ReturnMultiple: Array of Variant;
    begin
      Result[0]:= 'hi';
      Result[1]:= 5;
      Result[2]:= 5.5;
      Result[3]:= True;
    end;

  6. #6
    Join Date
    Mar 2006
    Posts
    3,051
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    As long as you manipulate GLOBAL variables in the function, you can use them other places in the script. There may be other better ways to do it, but that's how I do it.

    For example:

    Code:
    Program ReturnTheVars;
    var a,b,c:integer;
    
    procedure ChangeVars(e,f,g:integer);
    begin
      e:=e+1;
      f:=f+10;
      g:=g+100;
    end;
    
    begin
      a:=5;
      b:=5;
      c:=5;
      ChangeVars(a,b,c);
      Writeln(IntToStr(a)+','+IntToStr(b)+','+InttoStr(c));
    end.
    That uses LOCAL variables (e,f,g), so it doesn't actually change the values returned.


    Code:
    Program ReturnTheVars;
    var a,b,c:integer;
    
    procedure ChangeVars(a,b,c:integer);
    begin
      a:=a+1;
      b:=b+10;
      c:=c+100;
    end;
    
    begin
      a:=5;
      b:=5;
      c:=5;
      ChangeVars(a,b,c);
      Writeln(IntToStr(a)+','+IntToStr(b)+','+InttoStr(c));
    end.
    That ALSO uses local variables. The a, b, and c that are changed are local to that procedure, not the global variable seen elsewhere in the script.

    Code:
    Program ReturnTheVars;
    var a,b,c:integer;
    
    procedure ChangeVars;
    begin
      a:=a+1;
      b:=b+10;
      c:=c+100;
    end;
    
    begin
      a:=5;
      b:=5;
      c:=5;
      ChangeVars;
      Writeln(IntToStr(a)+','+IntToStr(b)+','+InttoStr(c));
    end.
    That one uses the Global variables, so it changes all the values.

  7. #7
    Join Date
    Jul 2006
    Posts
    259
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    yea but my programming teacher said you should use as little global vars as possible so functions can be used for multiple programs
    "your always where you supposed to be"

  8. #8
    Join Date
    Mar 2006
    Posts
    3,051
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Yeah, it's bad coding practices, but I'm not that great of coder. Pretty much all self-taught. Anybody that has even had a recent introductory class to pascal would have a leg up on me.

    However, I am usually able to get the spaghetti code to function as I want it to.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Function Return variables? How?
    By kodeejs in forum OSR Help
    Replies: 14
    Last Post: 08-19-2007, 02:10 AM
  2. How do I return an array of integer?
    By R0b0t1 in forum OSR Help
    Replies: 7
    Last Post: 06-27-2007, 03:42 AM
  3. Return Sig
    By -chaos- in forum Semi Stupid Pictures
    Replies: 5
    Last Post: 05-29-2007, 03:08 PM

Posting Permissions

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