Results 1 to 15 of 15

Thread: Function Return variables? How?

  1. #1
    Join Date
    Nov 2006
    Location
    Latvia
    Posts
    53
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Function Return variables? How?

    So i know how with function can return one variable! But i need return 3 or mucher varibales so how can i do that?

    Example how i think:

    SCAR Code:
    function Nothing(name:string):string; // here need return 3 variables maybe in array if posible.
      begin
        // here is all code ... etc. And
       Result[0]:='sdfssddf'; // first
       Result[1]:='sdfssddf'; // second
       Result[2]:='ssaddfsdf'; // thir
      end;

    So Who know how to return mucher that one variable from function? Plz help!

    Edit: But i think now, how can i giv that results something, i need then for loop for returning? or something hmmm...

  2. #2
    Join Date
    Feb 2006
    Location
    London, England
    Posts
    2,045
    Mentioned
    2 Post(s)
    Quoted
    0 Post(s)

    Default

    PHP Code:
    program New;

    function 
    something: Array of String;
    begin
      setArrayLength
    (Result2);
      
    Result[0] := '1';
      
    Result[0] := '2';
      
    Result[0] := '3';
    end
    maybe something like that
    SRL Wiki | SRL Rules | SRL Stats
    Ultimate SCAR Scripting Tutorial | Starblaster100's Auth System | Join the official SRL IRC now!


    Help Keep SRL Alive! Please disable Advert Blockers on SRL! Help Keep SRL Alive!


  3. #3
    Join Date
    Nov 2006
    Location
    Latvia
    Posts
    53
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thx a lot for idea, i will try!

  4. #4
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    SCAR Code:
    procedure something(var string1, string2: string);
    begin
      string1 := 'one';
      string2 := 'two';
    end;

    Star's will work better for your situation.
    Interested in C# and Electrical Engineering? This might interest you.

  5. #5
    Join Date
    Nov 2006
    Location
    Latvia
    Posts
    53
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    yeah looks like i need to use procedure. Because with function i can`t assign false values. And when i use my function i got errors... i think i do something wrong. Can anyone edit and help me with this?

    SCAR Code:
    function MakeMonsterNames(name:string):array of string;
    var
      l:integer;
       begin
         setArrayLength(Result, 2);
         l:=Length(name);
           if l<=6 then
             begin
               Writeln('Need longer Text!');
                Result[0]:=False;
                Result[0]:=False;
                Result[0]:=False;
                 Exit;
             end;
           if l>=6 then
             begin
                Result[0]:=copy(name, 1, 3);
                Result[0]:=copy(name, 4, 3);
                Result[0]:=copy(name, 7, 3);
             end;

       end;

    I think i here make something diferent with that names. First i will count them all and then divide... But first i need understand how to return mucher string values.

  6. #6
    Join Date
    Feb 2006
    Location
    London, England
    Posts
    2,045
    Mentioned
    2 Post(s)
    Quoted
    0 Post(s)

    Default

    you can't have Result[0] := false in your above post, because you are trying to return strings (as stated by array of string and not booleans (which the world "False" is)
    SRL Wiki | SRL Rules | SRL Stats
    Ultimate SCAR Scripting Tutorial | Starblaster100's Auth System | Join the official SRL IRC now!


    Help Keep SRL Alive! Please disable Advert Blockers on SRL! Help Keep SRL Alive!


  7. #7
    Join Date
    Nov 2006
    Location
    Latvia
    Posts
    53
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ehh lol, im bot So nooby error

    Edit: So OK! But i little don`t understand how can i use that?
    SCAR Code:
    function MakeMonsterNames(name:string):array of string;
    var
      l:integer;
       begin
         setArrayLength(Result, 2);
         l:=Length(name);
           if l>=6 then
             begin
                Result[0]:=copy(name, 1, 3);
                Result[0]:=copy(name, 4, 3);
                Result[0]:=copy(name, 7, 3);
             end;
       end;
    begin
     function MakeMonsterNames('Deadly Spider');
    end.

    I think i need ... idk i have idea, but what you guys offer...

  8. #8
    Join Date
    Aug 2007
    Posts
    282
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by kodeejs View Post
    yeah looks like i need to use procedure. Because with function i can`t assign false values. And when i use my function i got errors... i think i do something wrong. Can anyone edit and help me with this?

    SCAR Code:
    function MakeMonsterNames(name:string):array of string;
    var
      l:integer;
       begin
         setArrayLength(Result, 2);
         l:=Length(name);
           if l<=6 then
             begin
               Writeln('Need longer Text!');
                Result[0]:=False;
                Result[0]:=False;
                Result[0]:=False;
                 Exit;
             end;
           if l>=6 then
             begin
                Result[0]:=copy(name, 1, 3);
                Result[0]:=copy(name, 4, 3);
                Result[0]:=copy(name, 7, 3);
             end;

       end;

    I think i here make something diferent with that names. First i will count them all and then divide... But first i need understand how to return mucher string values.
    fist of all i think you want result[0] result1] and result[2] not all 0s...

    and if the length is 6 then you have it doing both copying and false.

    and im not sure about the false part. unless you do a mix of the ideas... for example:

    SCAR Code:
    function MakeMonsterNames(var var1, var2, var3: String; name:string): Booleen;
    var
      l:integer;
       begin
         setArrayLength(Result, 2);
         l:=Length(name);
           if l<=6 then
             begin
               Writeln('Need longer Text!');
                Result:=False;
                 Exit;
             end;
           if l>=6 then
             begin
                Result:=True
                var1:=copy(name, 1, 3);
                var2:=copy(name, 4, 3);
                var3:=copy(name, 7, 3);
             end;

       end;

    modify it so it compiles.. not sure if it will and so it works for your needs

  9. #9
    Join Date
    Nov 2006
    Location
    Latvia
    Posts
    53
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by dvdcrayola View Post
    fist of all i think you want result[0] result1] and result[2] not all 0s...

    and if the length is 6 then you have it doing both copying and false.

    and im not sure about the false part. unless you do a mix of the ideas... for example:

    SCAR Code:
    function MakeMonsterNames(var var1, var2, var3: String; name:string): Booleen;
    var
      l:integer;
       begin
         setArrayLength(Result, 2);
         l:=Length(name);
           if l<=6 then
             begin
               Writeln('Need longer Text!');
                Result:=False;
                 Exit;
             end;
           if l>=6 then
             begin
                Result:=True
                var1:=copy(name, 1, 3);
                var2:=copy(name, 4, 3);
                var3:=copy(name, 7, 3);
             end;

       end;

    modify it so it compiles.. not sure if it will and so it works for your needs

    But i need use that var1, var2, var3 in other procedure, but your function just return true or false... hmmm, is that be posible? O but then i better can use copy function in that my other procedure don`t need this function which return...

  10. #10
    Join Date
    Aug 2007
    Posts
    282
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    umm.. sorry but that didnt make much sense to me.. it stores what you want as what you input as var1 var2 and var3... so you can use those other procedures.

    do you understand?

  11. #11
    Join Date
    Jun 2007
    Location
    I'm not sure...
    Posts
    581
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Wouldn't you get an out of range error, because you are defining the length of the result array to 2, and not 3?
    I always thought that you had to set it as 3 to get access to Result[0]..Result[2] =/
    ---------------------------------------------------------


    Pm me if you need any math functions made. Me = l0ving t3h mathz

    ---------------------------------------------------------

  12. #12
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    Nope, but you can do

    SCAR Code:
    Var SomeArray: Array [5..123123] of Something;

    and not start on 0.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  13. #13
    Join Date
    Aug 2007
    Posts
    282
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    you dont set arrays as a 2 or a 3.. you do [0..2] which means it ranges from 0 to 2.. so 0 1 2.. 3 numbers.

  14. #14
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    Yeah, I know. But I'm fairly sure you can do it starting at something other than 0.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  15. #15
    Join Date
    Jun 2007
    Location
    I'm not sure...
    Posts
    581
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Yeah, but for SetArrayLength(Whatever,2) only lets you use Whatever[0] and Whatever[1], right?

    Btw, I know you can define variables like that, but we're talking about SetArrayLength. (At least I think so XD)

    Just to clarify:
    SCAR Code:
    Var
      Butt:Array [0..2] of String;
    is the same as
    SCAR Code:
    Var
      Butt:Array of String;
    Begin
      SetArrayLength(Butt,3);
    End.
    ---------------------------------------------------------


    Pm me if you need any math functions made. Me = l0ving t3h mathz

    ---------------------------------------------------------

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 5
    Last Post: 11-10-2008, 01:11 AM
  2. Function and Procedure 'variables'.
    By Wizzup? in forum OSR Advanced Scripting Tutorials
    Replies: 11
    Last Post: 03-27-2008, 03:07 AM
  3. Return Sig
    By -chaos- in forum Semi Stupid Pictures
    Replies: 5
    Last Post: 05-29-2007, 03:08 PM
  4. return multiple vars in function
    By del_signo in forum OSR Help
    Replies: 7
    Last Post: 05-12-2007, 03:03 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
  •