Results 1 to 11 of 11

Thread: Procedures & Functions for Beginners

  1. #1
    Join Date
    Aug 2014
    Location
    Australia
    Posts
    932
    Mentioned
    53 Post(s)
    Quoted
    495 Post(s)

    Default Procedures & Functions for Beginners

    Procedures & Functions for Beginners
    By me, Incurable!

    Last updated 30th October, 2015


    NOTE: I wrote this in a couple of hours and then rewrote the whole thing. I think I got everything but there might still be a few remnants of the previous tutorial leftover. If you spot anything that looks like it shouldn't be there, let me know!




    Over the last few months I've noticed that quite a lot of new scripters don't fully understand the difference between procedures and functions and don't know when to use them or how. This brief tutorial aims to explain the difference between procedures and functions and how to use them effectively. It will do this by writing the code for a rudimentary power miner. It assumes that you have already completed The Mayor's AIO scripting tutorial. It's important to note that this tutorial specifically discusses the use of procedures and functions in Lape and other Pascal derived languages, but it can be applied to other languages in a very general context.

    Now, let's get started!

    Section 1: The Difference


    We'll begin with the difference between procedures, functions, methods and routines. You've heard these words before, but the difference probably isn't very clear to you.

    Procedure: A (usually small) block of code that acts as a sub-program in a (usually larger) program. It executes its code line-by-line in a procedural fashion until no more lines remain to be executed. It can contain other procedures and functions, but it does not return a value.

    Example: This could be used to login a player. Note that the SRL-6 function players[currentPlayer].login() calls another function named isLoggedIn() which means that we don't need to use any if statement to check if we're logged in before calling it.

    Simba Code:
    1. procedure LoginPlayer();
    2. begin
    3.   writeLn('Logging in');
    4.    players[currentPlayer].login();
    5.   wait(randomRange(2000, 5000));
    6. end;

    In this case, our procedure will check to see if the player is logged in. If they're not, it will write a line to the Simba debug console, log the player in (if they're not already logged in), and wait for a random time between 2 and 5 seconds. No value has been returned, and we cannot use this procedure as a condition in any test, such as in an if statement or while loop.

    Function: A (usually small) block of code that acts as a sub-program in a (usually larger) program. It executes its code line-by-line in a procedural fashion until no more lines remain to be executed. It can contain other procedures and functions and should* return a value.

    Example: A simple demonstration of a function that will click on an ore rock and return a boolean defined by the results of the SRL-6 function mainScreen.findObject().

    Simba Code:
    1. // clickOre will return a boolean defined by whether or not an ore rock
    2. // was found and clicked on with mainScreen.findObject
    3. function clickOre(): boolean;
    4. var
    5.   x, y: integer;
    6. begin
    7.   writeLn('Clicking ore');
    8.   if (mainscreen.findObject(x, y, 7446732, 9, ['opper'], MOUSE_LEFT)) then
    9.     result := true;
    10. end;

    Unlike our procedure, a function can be used in a conditional test. We can actually make this code even shorter by directly calling the mainScreen.findObject() function and assigning its result to our own function's boolean result! Confused? I don't blame you. Here's how we do that:

    Simba Code:
    1. // clickOre will return a boolean defined by whether or not an ore rock
    2. // was found and clicked on with mainScreen.findObject()
    3. function clickOre(): boolean;
    4. var
    5.   x, y: integer;
    6.  
    7. begin
    8.   writeLn('Clicking ore');
    9.   result := mainscreen.findObject(x, y, 7446732, 9, ['opper'], MOUSE_LEFT);
    10. end;

    Now that we've written a function, here's an example of the same function being used in some pseudo-code:

    Simba Code:
    1. function mineOre(): boolean;
    2. begin
    3.   while the backpack isn't full do
    4.    if clickOre() then // <--- Here as a condition
    5.    begin
    6.      write: we found some ore!
    7.      wait until ore is mined
    8.    end
    9.  
    10.  if backpack is full
    11.    result = true
    12. end;

    * A function doesn't have to return a value, but it would be bad practice to declare a function and use it as a procedure. If you're not going to return anything then you should be using a procedure instead.

    Data types that can be returned: Everything! No really, as far as I know functions in Lape are able to return practically any type that you like. The most common return type in SRL-6 is a boolean, but you can return integers, doubles, strings, and even custom data types! This makes functions incredibly versatile and useful in almost every scenario.

    Method/routine: These two words are used to refer to all of the procedures and functions in a program. In other words, if someone mentions that they like your "methods" when talking about your script, they are usually referring to all of your procedures and functions. The same goes for routines. It's worth noting that not everybody uses them this way and may instead confuse them with the word procedure, but when talking about Lape specifically, it's not very useful to refer to a procedure as a method or routine when it is defined by the keyword procedure.

    This is a point of confusion for a lot of people that stems from the use of the words method and routine in other languages to refer to their versions of procedures and functions. However, in our usage (Lape) we use procedure and function as actual keywords, so they should not be referred to by any other name (thanks to @the bank; for clarification on this).

    Section 2: Correct Usage


    Now that we know the difference between procedures and functions we can discuss when you should actually use them. I'm just going to assume that this isn't completely clear to you yet. If it is, awesome, you can skip to section 3.

    Procedure: A procedure should be used when you need to execute a block of code but don't need to return any values. For example, our LoginPlayer() procedure wouldn't do us any good as a function because we aren't testing any conditions and will know if it worked by observing the results. We also can't turn it into a function in its current form because we have no conditions to test! Procedures can also be used to create a neater, more readable, and more maintainable script. By placing chunks of code into useful procedures, we can simplify a script and quickly find problems when they arise.

    Function: A function should be used when you want to test a condition and return the result of that test. Yup, pretty simple, right? That's because it really is. Because of their versatility, functions can be used in almost any scenario to test conditions and return the result. This is especially useful in RuneScape scripting where we need to know the state of our player and the game world at all times. I'll give you an example.

    Example:You're writing a power miner and want to keep mining until the backpack is full. Using a conditional test such as an if statement, we can test whether the backpack is full using the SRL-6 function tabBackpack.isFull(). First, let's take another look at our first example function:

    Simba Code:
    1. // clickOre will return a boolean defined by whether or not an ore rock
    2. // was found and clicked on with mainScreen.findObject()
    3. function clickOre(): boolean;
    4. var
    5.   x, y: integer;
    6. begin
    7.   writeLn('Clicking ore');
    8.   result := mainscreen.findObject(x, y, 7446732, 9, ['opper'], MOUSE_LEFT);
    9. end;

    ... we can use this function as a test inside of another function that uses a repeat..until loop nested inside of a while. This is the fleshed out version of the pseudo-code example above:

    Simba Code:
    1. // This function will mine ore while the SRL-6 function "tabBackpack.isFull()" is
    2. // returning false! By using the function as a test condition in a while loop,
    3. // we can use its result to know whether or not we need to mine another ore rock!
    4. function mineOre(): boolean;
    5. var
    6.   currentCount: integer;
    7.  
    8. begin
    9.   // Using "not" is the same as "while (tabBackpack.isFull() = false) do"
    10.   while (not tabBackpack.isFull()) do
    11.   begin
    12.     currentCount := tabBackpack.count(); // Get the number of items in the backpack
    13.     // Again, this is the same as "if (clickOre() = true) then"
    14.     if (clickOre()) then
    15.     begin
    16.       writeLn('Waiting while mining');
    17.       // Try and understand what this does and how it works!
    18.       repeat
    19.         wait(randomRange(100, 250));
    20.       until (tabBackpack.count() > currentCount)
    21.     end else
    22.     begin
    23.       writeLn('Cannot find ore, exiting');
    24.       exit(false); // See note below for an explanation of this
    25.     end;
    26.   end;
    27.  
    28.   result := true; // This line is only reachable if tabBackpack.isFull() is true!
    29. end;

    Did you notice the use of exit(false)? That should be fairly self-explanatory, but here's a quick explanation anyway. The statement exit is used to stop a method and exit out of it completely, moving on to the next step in the program. If a boolean parameter is added when called inside of a function, such as in this case, the result of that function will be the value of that boolean. So, to demonstrate again, the following function will always return true despite result being assigned as false.

    Simba Code:
    program ExitDemo;

    function someFunc(): boolean;
    var
      param: boolean;
    begin
      result := false;
      if (not result) then
        writeLn('result = false');

      exit(true);
    end;

    begin
      clearDebug();
      writeLn(someFunc());
    end.

    Try it for yourself. Copy/paste the code into a new program and hit run. What result gets printed out? What happens if you change result to true and the parameter of exit to false?

    Section 3: Effective Use



    This is a brief sample of SRL-6 functions and their return types:

    • tabBackpack.isFull(): boolean;
    • tabBackpack.count(): integer;
    • bankScreen.isOpen(): boolean;
    • bankScreen.open(): boolean;
    • collectBox.isOpen(): boolean;
    • chatBox.getXPBar(): integer;
    • chatBox.getTextOnLine(line): String;
    • lootScreen.getSlotBox(slot): TBox;


    ... as you can see, the majority of methods in the SRL-6 include are functions that return some value relevant to the function. This is done so that we may use these functions to be constantly testing the state of the game world and reacting accordingly. For example, in our mineOre() function we use tabBackpack.isFull() to test whether we should keep mining. Similarly, we use tabBackpack.count() to make the script wait until the backpack count is greater than the value stored in the integer type variable currentCount.

    It's important to quickly note that a function used as a condition is always executed and tested in order to get its result. An if statement with the condition not tabBackpack.isFull() will still execute the function tabBackpack.isFull() and use its condition as a result, regardless of whether we use the keyword not. Functions can be used to constantly test conditions and react accordingly. The following is a seemingly complex example of a number of functions being used in an event loop procedure in a smelting script. It is heavily commented to make it easier to understand. It's actually really simple once you understand how it works, but the number of conditionals can be daunting for some.

    Simba Code:
    1. procedure EventLoop();
    2. begin
    3.   // A failsafe to stop the script if the global variable of type boolean
    4.   // "IsScriptRunning" is false
    5.   if (not IsScriptRunning) then
    6.     exit;
    7.  
    8.   players[currentPlayer].login(); // Remember: this only logs in if we aren't logged in already
    9.   SetupScreen(); // Setup the screen
    10.  
    11.   ProgRep(); // Write a progress report to the Simba debug console
    12.  
    13.   // Test the result of a lodestone teleporting function
    14.   if (IL.lodeTele(LOCATION_LUMBRIDGE)) then
    15.     TelesDone += 1; // increment the global variable of type integer "telesDone" by 1
    16.  
    17.   // Test the result of a walking function
    18.   if (IL.walkThePath(SPS, PathLodeToBank)) then
    19.     repeat
    20.       // Test the result of a banking function
    21.       if (not openBank()) then
    22.       begin
    23.         // Report an error since openBank() didn't work. We know this because it returned false.
    24.         ReportError('openBank() failed', 'openbank');
    25.         break();
    26.       end else
    27.       begin
    28.         // Test the result of an ore withdrawing function
    29.         if (not withdrawOre()) then
    30.         begin
    31.           // Report an error since withdrawOre() didn't work. We know this because it returned false.
    32.           ReportError('withdrawOre() failed', 'withdrawore');
    33.           IsScriptRunning := false;
    34.         end;
    35.       end;
    36.  
    37.       // Test the result of a minimap rotating function
    38.       if (not minimap.setAngle(gaussRangeInt(288, 318))) then
    39.       begin
    40.         // Try walking to the furnace instead of setting the angle of the minimap, test the result
    41.         if (not IL.walkThePath(SPS, PathBankToFurn)) then // Try walking
    42.         begin
    43.           // Report an error since IL.walkThePath() didn't work. We know this because it returned false.
    44.           ReportError('walkPath(PathBankToFurn) failed', 'walkPath_BankToFurn');
    45.           break();
    46.         end;
    47.       end;
    48.  
    49.       wait(gaussRangeInt(200, 400)); // Wait a period of time between 200-400 seconds randomised to a Gaussian value
    50.  
    51.       // Test the result of a furnace finding function
    52.       if (not findFurnace()) then
    53.       begin
    54.         // Report an error since findFurnace() didn't work. We know this because it returned false.
    55.         ReportError('findFurnace() failed', 'findFurnace');
    56.         break();
    57.       end else
    58.         // Since findFurnace() returned true, test the result of a function that smelts the ore
    59.         if (not smeltOre()) then
    60.         begin
    61.           // Report an error since smeltOre() didn't work. We know this because it returned false.
    62.           ReportError('smeltOre() failed', 'smeltOre');
    63.           break();
    64.         end;
    65.  
    66.       // Test the result of a minimap rotating function
    67.       if (not minimap.setAngle(gaussRangeInt(18, 38))) then
    68.         // Try walking to the bank instead of setting the angle of the minimap, test the result
    69.         if (not IL.walkThePath(SPS, PathFurnToBank)) then // Try walking
    70.         begin
    71.           // Report an error since IL.walkThePath() didn't work. We know this because it returned false.
    72.           ReportError('walkPath(PathFurnToBank) failed', 'walkPath_FurnToBank');
    73.           break();
    74.         end;
    75.  
    76.       wait(gaussRangeInt(200, 400)); // Wait a period of time between 200-400 seconds randomised to a Gaussian value
    77.       ProgRep(); // Write a progress report to the Simba debug console
    78.       BreakHandler(); // Execute the break handling procedure
    79.     until ((not IsScriptRunning) or (not isLoggedIn()));
    80.     // ^ The previous repeat..until loop runs until IsScriptRunning is false or the player isn't
    81.     // logged in. IsScriptRunning is set to false if any of the condition checks fails.
    82.  
    83.     // Although this code is unreachable at first, it will still only execute if IsScriptRunning is false.
    84.     // It will not execute if the player has only logged out for some reason (for example, by disconnecting).
    85.     if (not IsScriptRunning) then
    86.     begin
    87.       writeLn('Ending script, be sure to post the proggy and any debug info ' +
    88.       'to the thread! :D');
    89.     end;
    90. end;

    Hopefully that procedure wasn't too complicated and the comments did a good enough job of explaining how multiple functions can be used to test certain conditions and react accordingly.

    Section 4: Rudimentary Powerminer Demo


    The following code is the complete program that we have written a couple of functions for already: a rudimentary power miner! It should work, so go ahead and copy/paste it or write it out manually (recommended). Once that's done, you can run it after standing at the Varrock East Mine logged in OR out in the following position. Remember that you're running it to try and understand it, not to use as an actual script!

    Setup location:



    Script:

    Simba Code:
    1. program ProcAndFuncTutMiner;
    2. {$DEFINE SMART}
    3. {$I SRL-6/SRL.simba}
    4.  
    5. // Remember that this is a RUDIMENTARY power miner. It should not be used
    6. // for an extended period of time nor should it be used on anything but a
    7. // throw away account. It is for demonstration purposes only.
    8.  
    9. var
    10.   KeepMining: boolean; // A global variable that will be used as a condition to
    11.                        // test whether the script should continue running!
    12.  
    13. procedure DeclarePlayers();
    14. begin
    15.   setLength(players, 1);
    16.   with players[0] do
    17.   begin
    18.     loginName := 'username';
    19.     password := 'password';
    20.     isActive := true; // Ignore
    21.     isMember := false; // Is the account a member?
    22.     world := 0; // Ignore
    23.   end
    24.   currentPlayer := 0; // Ignore
    25. end;
    26.  
    27. // This procedure will setup the script by executing a series of pre-written
    28. // procedures and setting a few boolean variables!
    29. procedure SetupScript();
    30. begin
    31.   smartShowConsole := false; // Disable the SMART console box
    32.   SetupSRL(); // Setup the SRL-6 include
    33.   disableSRLDebug := true; // Disable the SRL-6 include debug options
    34.   clearDebug(); // Clear the Simba debug console so we can see our own writeLn's
    35.   DeclarePlayers(); // Declare the player(s) to be used
    36.   writeLn('Script setup complete!'); // Write a line to the Simba debug console
    37.   KeepMining := true; // Set the global variable "KeepMining" to true for use in
    38.                       // the "main" procedure
    39. end;
    40.  
    41.  
    42. // This procedure acts as a simple wrapper to login and wait 2-5 seconds. It's
    43. // actually not totally necessary and just serves as a demo of a potentially
    44. // useful procedure.
    45. procedure LoginPlayer();
    46. begin
    47.   if (not isLoggedIn()) then
    48.   begin
    49.     writeLn('Logging in');
    50.     players[currentPlayer].login();
    51.     wait(randomRange(2000, 5000));
    52.   end;
    53. end;
    54.  
    55. // Again, this is just a wrapper for some basic functions. It's not totally
    56. // necessary, but serves as a good demo of a potentially useful procedure.
    57. // Can you figure out why I didn't combine SetupScreen and LoginPlayer into a
    58. // bigger procedure? Or why I didn't include them both in SetupScript?
    59. procedure SetupScreen();
    60. begin
    61.     writeLn('Setting up the screen');
    62.     mainScreen.setAngle(MS_ANGLE_HIGH);
    63.     mainScreen.setZoom(false);
    64.     minimap.setAngle(MM_DIRECTION_SOUTH);
    65. end;
    66.  
    67.  
    68. // clickOre will return a boolean defined by whether or not an ore rock
    69. // was found and clicked on with mainScreen.findObject(). We can use this
    70. // boolean in the next function!
    71. function clickOre(): boolean;
    72. var
    73.   x, y: integer;
    74.  
    75. begin
    76.   writeLn('Clicking ore');
    77.   result := mainscreen.findObject(x, y, 7446732, 9, ['opper'], MOUSE_LEFT);
    78. end;
    79.  
    80. // This function will mine ore while the SRL-6 function "tabBackpack.isFull()" is
    81. // returning false! By using the function as a test condition in a while loop,
    82. // we can use its result to know whether or not we need to mine another ore rock!
    83. function mineOre(): boolean;
    84. var
    85.   currentCount: integer;
    86.  
    87. begin
    88.   // Using "not" is the same as "while (tabBackpack.isFull() = false) do"
    89.   while (not tabBackpack.isFull()) do
    90.   begin
    91.     currentCount := tabBackpack.count(); // Get the number of items in the backpack
    92.     // Again, this is the same as "if (clickOre() = true) then"
    93.     if (clickOre()) then
    94.     begin
    95.       writeLn('Waiting while mining');
    96.       // Try and understand what this does and how it works!
    97.       while (tabBackpack.count() = currentCount) do
    98.         wait(randomRange(100, 250));
    99.     end else
    100.     begin
    101.       writeLn('Cannot find ore, exiting');
    102.       exit(false);
    103.     end;
    104.   end;
    105.  
    106.   result := tabBackpack.isFull() // Assign the result of the function tabBackpack.isFull()
    107.                                  // to this function's result
    108. end;
    109.  
    110. // This is the procedure that will be repeatedly executed in the "while (KeepRunning) do"
    111. // loop setup in our main procedure!
    112. procedure EventLoop();
    113. begin
    114.   writeLn('Entering the event loop...');
    115.   LoginPlayer();
    116.   SetupScreen();
    117.   if (mineOre()) then
    118.     tabBackpack.dropItems()
    119.   else
    120.     KeepMining := false;
    121.   writeLn('We have reached the end of the event loop...');
    122. end;
    123.  
    124. // This procedure will log the player out. Usually you would do some more stuff
    125. // in a procedure like this such as freeing DTMs and bitmaps, but since we don't
    126. // have any of those, this is just a very basic wrapper for logging out.
    127. procedure EndScript();
    128. begin
    129.   writeLn('Logging out and ending script');
    130.   players[currentPlayer].logout();
    131. end;
    132.  
    133. // Do you understand what's going on in this main procedure?
    134. // Why is it so short?
    135. begin
    136.     SetupScript();
    137.     while (KeepMining) do
    138.       EventLoop();
    139.     EndScript();
    140. end.

    ... and that's everything! By now you should understand the difference between a procedure and a function and have a good idea of how and when you can utilise them best. If you don't, then it's probably my fault for writing an unclear tutorial! If you have any problems or questions, please don't hesitate to post them here no matter how old this thread is. If you tag me by wrapping my name in tags I will get a notification and be able to answer you sooner rather than never.

    Good luck with your scripting adventures, be sure to tag me in your first script if you utilise functions: I want to know if I actually taught anyone anything.
    Last edited by Incurable; 03-07-2016 at 05:16 AM.



    New to scripting? Procedures & Functions for Beginners
    Do you use your computer at night? Just get f.lux

  2. #2
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,164
    Mentioned
    26 Post(s)
    Quoted
    433 Post(s)

  3. #3
    Join Date
    Mar 2013
    Posts
    1,010
    Mentioned
    35 Post(s)
    Quoted
    620 Post(s)

    Default

    Simba Code:
    // Login only if we're not logged in
      if (not isLoggedIn()) then
        players[currentPlayer].login();
    isLoggedIn is called by players[currentPlayer].login(); so no need to use isLoggedIn in your script! Don't be inefficient
    Nice work
    #slack4admin2016
    <slacky> I will build a wall
    <slacky> I will ban reflection and OGL hooking until we know what the hell is going on

  4. #4
    Join Date
    Aug 2014
    Location
    Australia
    Posts
    932
    Mentioned
    53 Post(s)
    Quoted
    495 Post(s)

    Default

    Quote Originally Posted by Harrier View Post
    Simba Code:
    // Login only if we're not logged in
      if (not isLoggedIn()) then
        players[currentPlayer].login();
    isLoggedIn is called by players[currentPlayer].login(); so no need to use isLoggedIn in your script! Don't be inefficient
    Nice work
    I didn't know that, thanks. Seems a bit silly, but whateverz.



    New to scripting? Procedures & Functions for Beginners
    Do you use your computer at night? Just get f.lux

  5. #5
    Join Date
    Mar 2013
    Posts
    167
    Mentioned
    7 Post(s)
    Quoted
    62 Post(s)

    Default

    This should be posted outside of RS3 scripting section. An awesome tutorial that doesn't only pertain to RS3, but to scripting in general. I've been on these forums for awhile, and have never come across this tutorial. I even looked for this specific type of tutorial at one point!
    "To sleep, perchance to dream"

  6. #6
    Join Date
    Dec 2010
    Posts
    483
    Mentioned
    30 Post(s)
    Quoted
    328 Post(s)

    Default

    Quote Originally Posted by Incurable View Post
    Method/routine: These two words are used to refer to all of the procedures and functions in a program. In other words, if someone mentions that they like your "methods" when talking about your script, they are usually referring to all of your procedures and functions. The same goes for routines. It's worth noting that not everybody uses them this way and may instead confuse them with the word procedure, but when talking about Lape specifically, it's not very useful to refer to a procedure as a method or routine when it is, in fact, a procedure.

    This is a point of confusion for a lot of people and it stems from the usage of methods and routines in other languages (Java is a good example) as actual keywords, but in our case they are not keywords and should not be referred to in place of an actual keyword.
    Meh. You're right that the terminology comes from other languages. However, neither routine or method are actual keywords in Java, even if "method" is a popular word when talking about java. A method is essentially a member function, keep in mind that Java forces OOP.

    Therefore, one could think of TTimeMarker.getTime() as a method.

    Additionally, procedures very well can return something, or multiple things, if you pass by reference rather than passing by value.

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

    Default

    Quote Originally Posted by the bank View Post
    Additionally, procedures very well can return something, or multiple things, if you pass by reference rather than passing by value.
    That's when you use the out keyword in the procedure's declaration to specify a variable that data will be outputted to, correct?
    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

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

    Default

    Quote Originally Posted by KeepBotting View Post
    That's when you use the out keyword in the procedure's declaration to specify a variable that data will be outputted to, correct?
    Or like function ReadFileString(FileNum:Integer;var s:string;x:integer):Boolean;

  9. #9
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Quote Originally Posted by KeepBotting View Post
    That's when you use the out keyword in the procedure's declaration to specify a variable that data will be outputted to, correct?
    Yes, tho out is currently just an alias for var. out is preferred whenever the current value stored in the variable is going to be ignored.
    Last edited by slacky; 02-12-2016 at 06:42 PM.
    !No priv. messages please

  10. #10
    Join Date
    Dec 2010
    Posts
    483
    Mentioned
    30 Post(s)
    Quoted
    328 Post(s)

    Default

    Quote Originally Posted by KeepBotting View Post
    That's when you use the out keyword in the procedure's declaration to specify a variable that data will be outputted to, correct?
    Correct. Essentially, passing by value will make a physical copy of the variable in memory and use that within the scope of the function. Passing by reference passes that exact object in memory (think: pointer) and anything you do to it within the function scope will affect it outside of the scope as well.

  11. #11
    Join Date
    Aug 2014
    Location
    Australia
    Posts
    932
    Mentioned
    53 Post(s)
    Quoted
    495 Post(s)

    Default

    Quote Originally Posted by the bank View Post
    Meh. You're right that the terminology comes from other languages. However, neither routine or method are actual keywords in Java, even if "method" is a popular word when talking about java. A method is essentially a member function, keep in mind that Java forces OOP.

    Therefore, one could think of TTimeMarker.getTime() as a method.

    Additionally, procedures very well can return something, or multiple things, if you pass by reference rather than passing by value.
    Sorry for the late reply.

    You're right, I don't know why I remembered "method" as a keyword. I'll edit that to make it more clear. Thanks!

    Quote Originally Posted by Vusn View Post
    This should be posted outside of RS3 scripting section. An awesome tutorial that doesn't only pertain to RS3, but to scripting in general. I've been on these forums for awhile, and have never come across this tutorial. I even looked for this specific type of tutorial at one point!
    Thank you, I'll see what I can do.

    EDIT: I've taken another look around the forum and can't really see where else I would put this. Do you have a suggestion? Where did you go when looking for this kind of tutorial?
    Last edited by Incurable; 03-07-2016 at 05:18 AM.



    New to scripting? Procedures & Functions for Beginners
    Do you use your computer at night? Just get f.lux

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
  •