Results 1 to 12 of 12

Thread: Functions with mutliple results

  1. #1
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default Functions with mutliple results

    Is it possible to have a function return more than one result consisting of different variables? and if so, how?
    E.g. Have a function return both a boolean and an integer

  2. #2
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

  3. #3
    Join Date
    Oct 2010
    Location
    Under a bridge
    Posts
    648
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Yes in create a type and make it return that,
    Type
    boolInt = record
    bool = Boolean;
    Number = Integer;

    and then do Func Name:boolInt;
    and use it by
    Function Derp():boolInt;
    Her := Derp();

    then Her.bool = true/false
    and Her.Number will be a interger

    E: Look at shut who ninja'd me it is so much simpler i forgot about it mine is long winded
    Quote Originally Posted by DD on IRC
    wanted to troll the troll

  4. #4
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    Quote Originally Posted by Shuttleu View Post
    sure, just with it in the header

    Simba Code:
    function something(var i: Integer): Boolean;
    it will return a boolean as the result
    and it will return a integer in i

    ~shut
    ah, I slightly get it but I've got a few more questions, if you don't mind

    Once the function runs how would the results be set e.g.:

    Simba Code:
    function something(var i: Integer): Boolean;
    begin
      if something then
        result := true //boolean
        result := 44
    end;

    would that set both variables or am i doing it wrong?

    Edit: @Troll: i'm gonna try it now, brb
    Last edited by HT BaaFly; 01-03-2012 at 08:23 PM.

  5. #5
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    Quote Originally Posted by HT BaaFly View Post
    ah, I slightly get it but I've got a few more questions, if you don't mind

    Once the function runs how would the results be set e.g.:

    Simba Code:
    function something(var i: Integer): Boolean;
    begin
      if something then
        result := true //boolean
        result := 44
    end;

    would that set both variables or am i doing it wrong?
    it would be like so
    Simba Code:
    function something(var i: Integer): Boolean;
    begin
      if something then
        result := true //boolean
        i := 44
    end;

    ~shut

  6. #6
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    Quote Originally Posted by Shuttleu View Post
    it would be like so
    Simba Code:
    function something(var i: Integer): Boolean;
    begin
      if something then
        result := true //boolean
        i := 44
    end;

    ~shut
    so i works like a global variable?

    another point, are things between the brackets always input and not outputs?

    function something(var i: Integer): Boolean;

  7. #7
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

  8. #8
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    ok thanks a lot man I love you

    +ripped everyone that helped

  9. #9
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Don't rep me.. only stating what troll posted.

    Simba Code:
    program new;

    type
      return = record
        Int: Integer;
        bool: Boolean;
      end;

    Function Returnstwo(I: integer): return;
    begin
      Result.bool:= true;
      Result.Int:= 3;
    end;
    I am Ggzz..
    Hackintosher

  10. #10
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    thanks a lot for making it clearer just one question about troll's method: outside of the function, how would you set the result
    e.g.:

    boolean := Returnstwo;
    int := Returnstwo;

    simple as that or what?

  11. #11
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    Simba Code:
    Var
      I : Integer;
      B : Boolean;

    I := Returnstwo.Int
    B := Returnstwo.bool

  12. #12
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    much much clearer now thanks to everyone

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
  •