Results 1 to 22 of 22

Thread: Make a function return two values (Integer and Boolean)

  1. #1
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default Make a function return two values (Integer and Boolean)

    Simba Code:
    Function MineRock(WutRock:Integer):Boolean;

    Got that.
    Want it to return the Boolean like it already does, AND an Integer (planning to make it how many rocks with ores it found).
    How Do?

  2. #2
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Function MineRock(WutRock:Integer, var ProducedInt: Integer):Boolean;

    ?

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  3. #3
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Um, so then how would I call/use that elsewhere to find out how many?
    Like Writeln(IntToStr(WHAT?!));

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

    Default

    How do? What u mean?

    Like this?

    Simba Code:
    program new;

    type
      Custom = record
        Bool: boolean;
        Int: Integer;
      end;


    Function LetsReturnTwoValues: Custom;
    begin
      //Do stuff to get some results/values..
      //.................
      //.................

      //Return two values..
      Result.Bool:= True;
      Result.Int:= 5035
    end;

    Procedure AssignTwoValues;
    var
      TwoVals: Custom;    //Notice the Custom type..
    begin
      //This will Access/Assign the two values.. NOT return..

      writeln(TwoVals.Bool);//Accessing

      TwoVals.Bool:= False;  //Assigning
      TwoVals.Int:= 5252352;
    end;
    I am Ggzz..
    Hackintosher

  5. #5
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    I don't get the AssignTwoValues :/

    Everything above that seems to be what I want though hmmm

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

    Default

    It's just a function I made to I guess show you how to access the values you have stored..


    Simba Code:
    //That function above.. has now stored it's results in Bool and Int of the Custom Record right?
    //Now lets access those values so we can do stuff with them..

    var
      Rock: Custom;

    begin
      writeln(Rock.Bool); //Accessing the values of Rock which is of type custom.. should print true..
      Writeln(Rock.Int);  //This should print that 5035..
    end.
    I am Ggzz..
    Hackintosher

  7. #7
    Join Date
    Oct 2008
    Location
    C:\Simba\Includes\
    Posts
    7,566
    Mentioned
    19 Post(s)
    Quoted
    180 Post(s)

    Default

    Based on what you want:

    Simba Code:
    var
      ret : Integer;

    if(MineRock(ROCK_IRON, ret))then
      WriteLn(IntToStr(ret));

    However, I'd suggest a Type like ggzz posted.

    Simba Code:
    type
      Custom = record
        Bool : Boolean;
        Int   : Integer;
    end;

    function retValues() : Custom;
    begin
      with Result do
      begin
        Bool := True;
        Int   := 123;
      end;
    end;

    procedure printValues();
    var
      ret : Custom;
    begin
      ret := retValues();
      WriteLn(BoolToStr(ret.Bool));
      WriteLn(IntToStr(ret.Int));
    end;
    Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
    { MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }

    When posting a bug, please post debug! Help us, help you!

    I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
    If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.


    SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.


  8. #8
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    How do I do something like
    Simba Code:
    If MineRock(Players[CurrentPlayer].Integers[1]).Bool=True Then
    Last edited by YoHoJo; 01-07-2012 at 05:26 AM.

  9. #9
    Join Date
    Oct 2008
    Location
    C:\Simba\Includes\
    Posts
    7,566
    Mentioned
    19 Post(s)
    Quoted
    180 Post(s)

    Default

    I'm confused on what you want to accomplish...?
    Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
    { MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }

    When posting a bug, please post debug! Help us, help you!

    I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
    If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.


    SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.


  10. #10
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    I want the function to return TRUE if rock was found/clicked AND I want it to return how many rocks were found.

    Like I want to use it like

    Simba Code:
    If MineRock('Iron') Then
    Begin
      AntiBan;
      Sex;
    End;

    And elsewhere in the script I want to do

    Simba Code:
    If MineRock<5 Then
    MoveToAnotherLocation;

  11. #11
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Something like this?
    Simba Code:
    var
      NumFound: Integer;

      If MineRock('Iron', NumFound) Then
      Begin
        AntiBan;
        Sex;
      End;

    An use the NumFound elsewhere? If it's used in multiple places it'll have to be a global variable. I dunno though, I might still be off track as to your request.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  12. #12
    Join Date
    Oct 2008
    Location
    C:\Simba\Includes\
    Posts
    7,566
    Mentioned
    19 Post(s)
    Quoted
    180 Post(s)

    Default

    Simba Code:
    type
      TRock = record
        Found : Boolean;
        HowMany : Integer;
    end;

    function MineRock(Which : Integer) : TRock;
    begin
      // Do mining stoof
      with Result do
      begin
        Found := True; // Could be used in a TPA and set True/False depending if it was found
        HowMany := 3; // Same idea with TPA, Length(TPA)
      end;
    end;

    procedure MainLoop;
    var
      pRock : TRock;
    begin
      pRock := MineRock(ROCK_IRON);
      if(pRock.HowMany < 5)then
        MoveToAnotherLocation;
    end;

    Something like that?
    Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
    { MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }

    When posting a bug, please post debug! Help us, help you!

    I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
    If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.


    SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.


  13. #13
    Join Date
    Oct 2006
    Posts
    1,190
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    Can you use out?



  14. #14
    Join Date
    Nov 2011
    Posts
    1,532
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by YoHoJo View Post
    How do I do something like
    Simba Code:
    If MineRock(Players[CurrentPlayer].Integers[1]).Bool=True Then
    This isn't java so I think you must pass your results to a struct first?

    Simba Code:
    result:= MineRock(Players[CurrentPlayer].Integers[1])
    if result.bool = true then
      ;//do whatever you want?

  15. #15
    Join Date
    Dec 2007
    Location
    192.168.1.73
    Posts
    2,439
    Mentioned
    6 Post(s)
    Quoted
    119 Post(s)

    Default

    Instead of creating a whole new type, surely you could just create a tVariantArray. Would save the messing about with with..dos and all that. Wouldn't really be that complex:

    Simba Code:
    program new;

    function returnTwoVals(val1: integer; val2: boolean): tVariantArray;
    begin
      Result := [val1, val2];
    end;

    var
    tva: tVariantArray;
    begin
      tva := returnTwoVals(5,true);
      writeLN(intToStr(tva[0]) + ', ' + boolToStr(tva[1]));
    end.
    Last edited by Richard; 01-07-2012 at 12:44 PM.

  16. #16
    Join Date
    Oct 2006
    Posts
    1,190
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    You can use out and have the function return two variables, you can have it true for the rock click and also return 8 for the number of found rocks, sorry I can't provide an example if by the time I'm home and remember I will try to post one up



  17. #17
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Why is this being so over complicated?

    function MineRock(Rock: Integer; var numRock: Integer): Boolean;

    When you put 'var' in front of a parameter you can use that variable inside the function and ooutside.

    So, with the example I just used:
    Simba Code:
    if MineRock(rock, number) then
      Writeln('Found '+toStr(number));

  18. #18
    Join Date
    Jul 2007
    Location
    Right now? Chair.
    Posts
    8,488
    Mentioned
    3 Post(s)
    Quoted
    12 Post(s)

    Default

    Quote Originally Posted by NCDS View Post
    Why is this being so over complicated?

    function MineRock(Rock: Integer; var numRock: Integer): Boolean;

    When you put 'var' in front of a parameter you can use that variable inside the function and ooutside.

    So, with the example I just used:
    Simba Code:
    if MineRock(rock, number) then
      Writeln('Found '+toStr(number));
    this

    -RM

    I & I know Zion. It is in the spirit, body and mind of every one of us
    RMouse(obj: TMSIObject): boolean;

  19. #19
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    I'm still lost here, :/.

    I have the function MineRock(WutRock:Integer); (Wutrock (1, 2, 3, etc etc) just means iron, coal, tin, etc.

    I want to be able to do something like

    Simba Code:
    If MineRock.Boolean Then blalbalbal
    AND
    Simba Code:
    WriteLn(IntToStr(MineRock.Integer)));

    With the same function.

    So, RM and NCDS are saying

    Simba Code:
    if MineRock(rock, number) then
      Writeln('Found '+toStr(number));

    So um, how would I assign a value to 'number'?
    Like let's say I got
    Simba Code:
    FindColorsSpiralTolerance(MSCX,MSCY,OrePts,2434854,SearchBox.x1,SearchBox.y1,SearchBox.x2,SearchBox.y2,10);

    How would I make the number of rocks found, in our case here 'number' := OrePts (OrePts right now ofc is an TPA).

  20. #20
    Join Date
    Nov 2006
    Posts
    2,369
    Mentioned
    4 Post(s)
    Quoted
    78 Post(s)

    Default

    Like this?
    Simba Code:
    program new;
    type
      MineRockInfo = record
        Boolean: Boolean;//Might want to change the variable name 'Boolean' to something like 'found'
        Integer: Integer;//Might want to change the variable name 'Integer' to something like 'amount'
      end;

    function MineRock: MineRockInfo;
    begin
      Result.Boolean := True;
      Result.Integer := 5;
    end;


    begin
      Writeln(BoolToStr(MineRock.Boolean));
      Writeln(IntToStr(MineRock.Integer));
    end.
    That would however call the function twice that we don't want.

    Here is a better example:
    Simba Code:
    program new;

    type
      MineRockInfo = record
        Boolean: Boolean;//Might want to change the variable name 'Boolean' to something like 'found'
        Integer: Integer;//Might want to change the variable name 'Integer' to something like 'amount'
      end;

    var
      MineInfo: MineRockInfo;

    function MineRock: MineRockInfo;
    begin
      Result.Boolean := True;
      Result.Integer := 5;
    end;


    begin
      MineInfo := MineRock;//MineRock only being called once!
      Writeln(BoolToStr(MineInfo.Boolean));
      Writeln(IntToStr(MineInfo.Integer));
    end.
    Quote Originally Posted by DeSnob View Post
    ETA's don't exist in SRL like they did in other communities. Want a faster update? Help out with updating, otherwise just gotta wait it out.

  21. #21
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Thanks for clarification I also talked to Kyle and I think I've gotten it figured out thanks everyone. Plan to release another script in the next few weeks.
    Going to be called Dr. Dick.

  22. #22
    Join Date
    Jun 2008
    Location
    United States
    Posts
    818
    Mentioned
    60 Post(s)
    Quoted
    90 Post(s)

    Default

    Quote Originally Posted by YoHoJo View Post
    I'm still lost here, :/.

    I have the function MineRock(WutRock:Integer); (Wutrock (1, 2, 3, etc etc) just means iron, coal, tin, etc.

    I want to be able to do something like

    Simba Code:
    If MineRock.Boolean Then blalbalbal
    AND
    Simba Code:
    WriteLn(IntToStr(MineRock.Integer)));

    With the same function.

    So, RM and NCDS are saying

    Simba Code:
    if MineRock(rock, number) then
      Writeln('Found '+toStr(number));

    So um, how would I assign a value to 'number'?
    Like let's say I got
    Simba Code:
    FindColorsSpiralTolerance(MSCX,MSCY,OrePts,2434854,SearchBox.x1,SearchBox.y1,SearchBox.x2,SearchBox.y2,10);

    How would I make the number of rocks found, in our case here 'number' := OrePts (OrePts right now ofc is an TPA).
    When you place 'var' in front of a parameter, you are letting the function/procedure know that not only are you passing a variable in, but that you are wanting the function/procedure to pass information out through the variable. If you put 'out' in front of a parameter, the function/procedure will ignore the current value of the variable, and will only pass out the modified version of it. So, if we do something like:
    Simba Code:
    Function MineRock(WutRock:Integer; out NumOfRocks):Boolean;

    and you then do:

    Simba Code:
    if MineRock(Rock, Number) then

    And somewhere in the function you put:

    Simba Code:
    NumOfRocks := Length(OrePts);

    Then after the function is through, you'll have the number of returned points stored within 'Number'. If you want to do further stuffz in the function to return just the rocks, you need to remember to set 'NumOfRocks' to that final value.
    Last edited by euphemism; 01-10-2012 at 05:01 PM.
    [10/14/13:19:03] <BenLand100> this is special relatively, just cleverly disguised with yachts

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
  •