Results 1 to 19 of 19

Thread: Proper Writeln function

  1. #1
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default Proper Writeln function

    So i started using functions in my scripts more to improve them but I was wondering if i could write a function without having to use a Boolean. I currently use:
    Simba Code:
    function WriteDebug(): boolean;
    begin
      ClearDebug;
      Writeln('*****************************');
      Writeln('Status:' + Status + '');
      Writeln('Spice steals:' + IntToStr(Stole_Spice) + '');
      Writeln('Ruby steals:' + IntToStr(Stole_Ruby) + '');
      Writeln('Runs:' + IntToStr(Runs) + '');
      WriteLn('Goal:' + '[' + How_Steal + ']'
      + '|' + IntToStr(StrToInt(How_Steal) - Steals)
      + ' Left to steal| ['
      + IntToStr(Round(Steals * 1.0 / StrToInt(How_Steal) * 100)) + '%]');
      Writeln('*****************************');
    end;

    but I am tired of getting:
    Code:
    [Hint] C:\Simba\Scripts\silabtheiv.simba(32:10): Variable 'Result' never used at line 31
    It spams up my debug box everytime I compile.

    Any tips?

  2. #2
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    Function Somthing:Integer/String/TPoint;?

  3. #3
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Your 'function' does not make use of the result, hence the declared result becomes an 'unused' variable, hence the hint.
    Simply rename 'function' to procedure instead and remove the result declaration.
    i.e.
    Simba Code:
    procedure WriteDebug();

  4. #4
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    Maybe I'm missing something, but why would you want to use a function for this instead of a procedure? The reason you get that result not used thing is because a function returns something. A boolean function retuns a true/false. That message means that you don't use what it returns, so you may as well use a procedure :/

  5. #5
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by BMWxi View Post
    Maybe I'm missing something, but why would you want to use a function for this instead of a procedure? The reason you get that result not used thing is because a function returns something. A boolean function retuns a true/false. That message means that you don't use what it returns, so you may as well use a procedure :/
    Then it has to skip to the procedure doesent it?

  6. #6
    Join Date
    Mar 2006
    Location
    Belgium
    Posts
    3,564
    Mentioned
    111 Post(s)
    Quoted
    1475 Post(s)

    Default

    Quote Originally Posted by rjj95 View Post
    Then it has to skip to the procedure doesent it?
    you want it to write the progressreport if it done something?

    Then why not try smthing like:
    Simba Code:
    if DoingSomething = True then progressreport;

    EDIT: OFFTOPIC

    Look at this post lol


    Shame on you!

    Creds to DannyRS for this wonderful sig!

  7. #7
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Sjoekeloe View Post
    you want it to write the progressreport if it done something?

    Then why not try smthing like:
    Simba Code:
    if DoingSomething = True then progressreport;

    EDIT: OFFTOPIC

    Look at this post lol


    Shame on you!
    why would you gravedig something I already confessed to from 2 years ago?

  8. #8
    Join Date
    Mar 2006
    Location
    Belgium
    Posts
    3,564
    Mentioned
    111 Post(s)
    Quoted
    1475 Post(s)

    Default

    Didn't see your confession sorry
    Cause It was funny when I saw that post.

    Creds to DannyRS for this wonderful sig!

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

    Default

    Quick and dirty: Functions are procedures that will return a result. Procedures are just blocks of code that do whatever you want them to, no results are returned. So if you're doing a progress report and all it does it call "writeln" a few times then it's better just to declare it as a procedure, not a function.

    Here's an example:

    Simba Code:
    Function TeleportToBank: Boolean;   //True or False will be returned from this
    begin
      if not LodestoneTeleport('Lunar Isle') then
        Exit;

      Result := WaitFunc(@NearBank, 10, 14000);
      {
       Or...
       if WaitFunc(@NearBank, 10, 14000) then
          Result := True
       else
          Result := False;
      }

    end;

    Procedure TeleportToBank;        //Nothing is returned
    begin
      if not LodestoneTeleport('Lunar Isle') then
        Exit;

      WaitFunc(@NearBank, 10, 14000);
    end;

    Main loop:

    Simba Code:
    if InvFull then
        if TeleportToBank then  //If this function returned true, then...
          Writeln('We are at the bank!')
        else
          Writeln('Wtf happened man?  I quit...');

    //Or, for a procedure...

    if InvFull then
       TeleportToBank;

    Understand?

    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..."


  10. #10
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    Quote Originally Posted by rjj95 View Post
    Then it has to skip to the procedure doesent it?
    What do you mean by skip to the procedure?

  11. #11
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    Quick and dirty: Functions are procedures that will return a result. Procedures are just blocks of code that do whatever you want them to, no results are returned. So if you're doing a progress report and all it does it call "writeln" a few times then it's better just to declare it as a procedure, not a function.

    Here's an example:

    Simba Code:
    Function TeleportToBank: Boolean;   //True or False will be returned from this
    begin
      if not LodestoneTeleport('Lunar Isle') then
        Exit;

      Result := WaitFunc(@NearBank, 10, 14000);
      {
       Or...
       if WaitFunc(@NearBank, 10, 14000) then
          Result := True
       else
          Result := False;
      }

    end;

    Procedure TeleportToBank;        //Nothing is returned
    begin
      if not LodestoneTeleport('Lunar Isle') then
        Exit;

      WaitFunc(@NearBank, 10, 14000);
    end;

    Main loop:

    Simba Code:
    if InvFull then
        if TeleportToBank then  //If this function returned true, then...
          Writeln('We are at the bank!')
        else
          Writeln('Wtf happened man?  I quit...');

    //Or, for a procedure...

    if InvFull then
       TeleportToBank;

    Understand?
    Yes

  12. #12
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Just make it function WriteDebug(); inetead of function WriteDebug(): boolean;
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Badâ„¢ before everyone gets laser pistols

  13. #13
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    Quote Originally Posted by KeepBotting View Post
    Just make it function WriteDebug(); inetead of function WriteDebug(): boolean;
    Like multiple people already told rjj95, there is no reason to have this as a function if he doesn't need it to return anything.

  14. #14
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by KeepBotting View Post
    Just make it function WriteDebug(); inetead of function WriteDebug(): boolean;
    Would result in a error.

  15. #15
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Quote Originally Posted by rjj95 View Post
    Would result in a error.
    Make it a procedure then so it doesn't have to return anything? It's what I do with my progress reports.
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Badâ„¢ before everyone gets laser pistols

  16. #16
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by KeepBotting View Post
    Make it a procedure then so it doesn't have to return anything? It's what I do with my progress reports.

    I did.

  17. #17
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Quote Originally Posted by rjj95 View Post
    I did.
    Oh okay. Lol.
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Badâ„¢ before everyone gets laser pistols

  18. #18
    Join Date
    Jan 2013
    Posts
    8
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    I'm also having the same problem as the TS. Some of the tips helped me. thanks!

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

    Default

    Quote Originally Posted by KeepBotting View Post
    Just make it function WriteDebug(); inetead of function WriteDebug(): boolean;
    instead*
    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.


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
  •