Page 1 of 2 12 LastLast
Results 1 to 25 of 26

Thread: Functions...

  1. #1
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default Functions...

    Hello guys. I have read through many, many tutorials but there is one thin I can't figure out. That is parameters of a function.
    Simba Code:
    function(var x, y : Integer) : Boolean;

    I get the fact that the result of the function is Boolean. But inside the paranthesis it has var x and y. This examPle is from kyle undefined's tut and he says the function gives x and y as a result?? Aren't they parameters?
    Thanks
    -Crit

    Ps: sorry for the block of text. on phone atm and I can't see a damn thing.

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

    Default

    It is impossible for a function to return 2 results the conventional way. i.e. no such thing as function abc: boolean and string;
    Hence to get around it, ppl have to load the result into the parameter.
    i.e.
    Simba Code:
    function abc(var x: integer): boolean;
    begin
      x:=blabla;
      if blabla then
        result:=true;
    end;
    So basically one of the result is stored as the parameter, and u just have to declare the parameter to use the "x" that the result returned.
    A lot of functions, such as FindColor, use this type of parameter-result storing.
    Last edited by riwu; 06-29-2012 at 10:14 AM.

  3. #3
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    So basically one of the result is stored as the parameter, and u just have to declare the parameter to use the "x" that the result returned.
    A lot of functions, such as FindColor, use this type of parameter-result storing.
    Why not store wit as a global variable. And secondly whats the difference between:
    Simba Code:
    function blah(var x: integer):Boolean
    And
    Simba Code:
    function blah(x: integer):Boolean
    Thanks
    -Crit

  4. #4
    Join Date
    Jul 2009
    Location
    Australia
    Posts
    667
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    Okay you use
    Simba Code:
    function blah(x: integer):Boolean
    if you want to call the function as say
    Simba Code:
    Blah(1);
    the 1 would then be the x. This is used in a script to give the ability to use the same function for a variety of different situations.
    As mentioned above, this gives an ease of use in re-use of the function so it would defeat the point to call the variables as global vars.

    ~Caotom
    Last edited by Caotom; 06-29-2012 at 02:53 PM.

  5. #5
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by Caotom View Post
    Okay you use
    Simba Code:
    function blah(x: integer):Boolean
    if you want to call the function as say
    Simba Code:
    Blah(1);
    the 1 would then be the x. This is used in a script to give the ability to use the same function for a variety of different situations.
    As far as I know adding var doesn't make a difference (someone correct me if I am wrong).
    As mentioned above, this gives an ease of use in re-use of the function so it would defeat the point to call the variables as global vars.

    ~Caotom
    I know you can call it somewhere else later on. But how does it differ from eg the common autocolor function where it returns Boolean and x/y??
    Thanks for your boss answer Caotom lol
    -Crit

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

    Default

    Apologize for confusing u, var is what that makes it a result rather than a parameter. So if u see a var in the parameter it means u have to declare it.

  7. #7
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    Apologize for confusing u, var is what that makes it a result rather than a parameter. So if u see a var in the parameter it means u have to declare it.
    Thank you very much mate. My confusion is over!! =D
    -Crit

  8. #8
    Join Date
    Feb 2012
    Location
    Somewhere, over the rainbow...
    Posts
    2,272
    Mentioned
    3 Post(s)
    Quoted
    45 Post(s)

    Default

    #just want to add, there are probably a lot of things which seem a bit 'iffy' to you right now, but the more you start to script the more you understand these matters.

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

    Default

    Quote Originally Posted by Crit Boy View Post
    Hello guys. I have read through many, many tutorials but there is one thin I can't figure out. That is parameters of a function.
    Simba Code:
    function(var x, y : Integer) : Boolean;

    I get the fact that the result of the function is Boolean. But inside the paranthesis it has var x and y. This examPle is from kyle undefined's tut and he says the function gives x and y as a result?? Aren't they parameters?
    Thanks
    -Crit

    Ps: sorry for the block of text. on phone atm and I can't see a damn thing.
    I'm no expert in the field, but I do know that Functions can result in anything, not just limited to booleans.

    Simba Code:
    function IsMoving: Boolean;
    function GetMyPos: TPoint;
    function CreateBitmap(w, h: integer): Integer;
    function Between(s1, s2, str: string): String;

    You can see function can result in whatever you want as these are just examples. Also from those examples, they don't have to have parameters at all.

    Another key note is if a function has (var something A): (something B); then that means it's, in essence, returning two variables. If any function has a "var" list in the parameters, that means those parameters will be supplied from the function, all you have to do is input an empty variable for the function to populate, in this case it's "something A". The second task is returning a result, this is the "something B". I'll write a quick example:

    Simba Code:
    program New;

      {
        Two parameters are required here, but because
        they're "var" then they'll be populated by
        the function.  Also, the function returns
        a String.
      }

      Function GetNumbers(var Xvalue, Yvalue: integer): String;
      begin
        Xvalue := 5;
        Yvalue := 10;
        result := IntToStr(Xvalue+Yvalue);
      end;

      Procedure WriteOurValues;
      var
        X,Y: Integer;     //These are our 'empty variables', they will be populated by the function
        Total: String;    //Same here
      begin
        Total := GetNumbers(X, Y);
        Writeln('Our total is '+Total);
      end;

    begin
      WriteOurValues;
    end.

    I hope that makes sense.
    Last edited by Flight; 06-29-2012 at 11:05 AM.

    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
    Feb 2012
    Location
    Australia
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    I'm no expert in the field, but I do know that Functions can result in anything, not just limited to booleans.

    Simba Code:
    function IsMoving: Boolean;
    function GetMyPos: TPoint;
    function CreateBitmap(w, h: integer): Integer;
    function Between(s1, s2, str: string): String;

    You can see function can result in whatever you want as these are just examples. Also from those examples, they don't have to have parameters at all.

    Another key note is if a function has (var something A): (something B); then that means it's, in essence, returning two variables. If any function has a "var" list in the parameters, that means those parameters will be supplied from the function, all you have to do is input an empty variable for the function to populate, in this case it's "something A". The second task is returning a result, this is the "something B". I'll write a quick example:

    Simba Code:
    program New;

      {
        Two parameters are required here, but because
        they're "var" then they'll be populated by
        the function.  Also, the function returns
        a String.
      }

      Function GetNumbers(var Xvalue, Yvalue: integer): String;
      begin
        Xvalue := 5;
        Yvalue := 10;
        result := IntToStr(Xvalue+Yvalue);
      end;

      Procedure WriteOurValues;
      var
        X,Y: Integer;     //These are our 'empty variables', they will be populated by the function
        Total: String;    //Same here
      begin
        Total := GetNumbers(X, Y);
        Writeln('Our total is '+Total);
      end;

    begin
      WriteOurValues;
    end.

    I hope that makes sense.
    Kinda. Are you actually using the result from the function though?? As far as I can see you get the function to output the x and y values which are added in the procedure. But when are you using the result and what does calling the function(x,y) do?
    I understand when you have parameters and then call the function/ procedure with the parameters but what do you do with this one??
    -Crit

    Ps: thanks for your interest in my problem you busy people
    I want to make a working script. Lets hope i can be bothered anytime soon

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

    Default

    Quote Originally Posted by Flight View Post
    I'm no expert in the field, but I do know that Functions can result in anything, not just limited to booleans.

    Simba Code:
    function IsMoving: Boolean;
    function GetMyPos: TPoint;
    function CreateBitmap(w, h: integer): Integer;
    function Between(s1, s2, str: string): String;

    You can see function can result in whatever you want as these are just examples. Also from those examples, they don't have to have parameters at all.

    Another key note is if a function has (var something A): (something B); then that means it's, in essence, returning two variables. If any function has a "var" list in the parameters, that means those parameters will be supplied from the function, all you have to do is input an empty variable for the function to populate, in this case it's "something A". The second task is returning a result, this is the "something B". I'll write a quick example:

    Simba Code:
    program New;

      {
        Two parameters are required here, but because
        they're "var" then they'll be populated by
        the function.  Also, the function returns
        a String.
      }

      Function GetNumbers(var Xvalue, Yvalue: integer): String;
      begin
        Xvalue := 5;
        Yvalue := 10;
        result := IntToStr(Xvalue+Yvalue);
      end;

      Procedure WriteOurValues;
      var
        X,Y: Integer;     //These are our 'empty variables', they will be populated by the function
        Total: String;    //Same here
      begin
        Total := GetNumbers(X, Y);
        Writeln('Our total is '+Total);
      end;

    begin
      WriteOurValues;
    end.

    I hope that makes sense.
    If u use the Xvalue and Yvalue solely to calculate ur final result (the string), wouldn't that be defeating the purpose of creating the two additional results?
    i.e.
    Simba Code:
    Function GetNumbers: String;
    begin
      result := IntToStr(5+10);
    end;
    will do the same thing.

    From my understanding its meant to be storing a different resultant variable to be used separately, i.e.
    Simba Code:
    a:=GetMMLevels('hp',color);
    if a<100 then
    begin
      writeln('dying! Initializing emergency teleport...');
      MouseItem(TAB_SLOT, mouse_left);
    end else
    if (color='orange') then
    begin
      writeln('switching to guthan..');
      //a procedure to switch to guthan
    end;
    maybe not a very good example but u get what im trying to say

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

    Default

    Quote Originally Posted by Crit Boy View Post
    Kinda. Are you actually using the result from the function though?? As far as I can see you get the function to output the x and y values which are added in the procedure. But when are you using the result and what does calling the function(x,y) do?
    I understand when you have parameters and then call the function/ procedure with the parameters but what do you do with this one??
    -Crit

    Ps: thanks for your interest in my problem you busy people
    Yes I'm making use of the result of the function.

    Simba Code:
    Procedure WriteOurValues;
      var
        X,Y: Integer;     //These are our 'empty variables', they will be populated by the function
        Total: String;    //Same here
      begin
        Total := GetNumbers(X, Y);   //We populate the 'Total' variable with the result from "GetNumbers(X, Y)"  The result itself is now 'Total'
        Writeln('Our total is '+Total);
      end;

    Quote Originally Posted by riwu
    If u use the Xvalue and Yvalue solely to calculate ur final result (the string), wouldn't that be defeating the purpose of creating the two additional results?
    You're right on the money, Riwu, but I was showing how to make use of Functions that have both a result as well as return variables (is that the correct term? I dunno...).
    Last edited by Flight; 06-29-2012 at 02:14 PM.

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


  13. #13
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    Yes I'm making use of the result of the function.

    Simba Code:
    Procedure WriteOurValues;
      var
        X,Y: Integer;     //These are our 'empty variables', they will be populated by the function
        Total: String;    //Same here
      begin
        Total := GetNumbers(X, Y);   //We populate the 'Total' variable with the result from "GetNumbers(X, Y)"  The result itself is now 'Total'
        Writeln('Our total is '+Total);
      end;



    You're right on the money, Riwu, but I was showing how to make use of Functions that have both a result as well as return variables (is that the correct term? I dunno...).
    I understand that you are making use of the x and y variables from the function but what happened to the result string? Is going to be displayed in the debug box. Anyway if I am just I confusing you too much with my questions I will just take ur examples and try them at home. Won't be for another week though.
    Thanks for your help anyway.
    -Crit
    I want to make a working script. Lets hope i can be bothered anytime soon

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

    Default

    Quote Originally Posted by Crit Boy View Post
    I understand that you are making use of the x and y variables from the function but what happened to the result string? Is going to be displayed in the debug box. Anyway if I am just I confusing you too much with my questions I will just take ur examples and try them at home. Won't be for another week though.
    Thanks for your help anyway.
    -Crit
    The result string get stored in another string variable "Total", u can do anything u want with result string, but in this case it will appear at the debug box since writeln is used.

  15. #15
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    The result string get stored in another string variable "Total", u can do anything u want with result string, but in this case it will appear at the debug box since writeln is used.
    Oh ok so because we declared 'Total' as a string it only accepts the string part of the function and not the x and y integers??
    I want to make a working script. Lets hope i can be bothered anytime soon

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

    Default

    Quote Originally Posted by Crit Boy View Post
    Oh ok so because we declared 'Total' as a string it only accepts the string part of the function and not the x and y integers??
    Correct, and because the "result type" of the function is a String rather than a Boolean we can store the result as a variable we declare, in this case 'Total'.

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


  17. #17
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    Correct, and because the "result type" of the function is a String rather than a Boolean we can store the result as a variable we declare, in this case 'Total'.
    Yay I finally understand it!! Just one more question.
    If we had this:
    Simba Code:
    program New;

    * Function GetNumbers(var number: integer): String;
    * begin
    * * Number := 15
    * * result := 'String result';
    * end;

    * Procedure WriteOurValues;
    * var
    * * Number, total: Integer;
    * begin
    * * Total := GetNumbers(Number);
    * * Writeln('Our total is '+IntToStr(Total));
    * end;

    begin
    * WriteOurValues;
    end.
    Would It use number as a result or am I dumb...? I know th coding might be a bit wrong but are basics right?
    -Crit

    Ps: don't know why there is asterisks in SIMBA code. iPod is retarded..
    I want to make a working script. Lets hope i can be bothered anytime soon

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

    Default

    Quote Originally Posted by Crit Boy View Post
    Yay I finally understand it!! Just one more question.
    If we had this:
    Simba Code:
    program New;

    * Function GetNumbers(var number: integer): String;
    * begin
    * * Number := 15
    * * result := 'String result';
    * end;

    * Procedure WriteOurValues;
    * var
    * * Number, total: Integer;
    * begin
    * * Total := GetNumbers(Number);
    * * Writeln('Our total is '+IntToStr(Total));
    * end;

    begin
    * WriteOurValues;
    end.
    Would It use number as a result or am I dumb...? I know th coding might be a bit wrong but are basics right?
    -Crit

    Ps: don't know why there is asterisks in SIMBA code. iPod is retarded..
    Nope. When u call a function by its function name (with its respective parameters/parameter-results), it will only return the result type of the function:
    function FunctionName(parameters: integer):String;
    So when u call this function, it will always return the result type that comes after ":", which is a string. To make use of the results u stored in the parameter, u will just use the declared variable.
    Simba Code:
    program New;

    Function GetNumbers(var number: integer): String;
    begin
      Number := 15;
      result := 'String result';
    end;

    Procedure WriteOurValues;
    var
      Number : Integer;
      StringStorer: String;
    begin
      StringStorer:=GetNumbers(Number);   //when u call this function, it will always return the string since that is its output
      writeln(StringStorer);  //this will hence returns 'String result', which is what u defined as the output result of the function

      //If u want to make use of the results in the parameter, just name it:
      Writeln('Our number is '+IntToStr(Number));
      //note that u'll have to call the function first before u can use its parameter-result.
    end;

    begin
      WriteOurValues;
    end.

    A simpler example would be FindColor(x,y,12345,1,1,1,1):boolean;
    So u would usually use the function by:
    Simba Code:
    procedure abc;
    var
      x,y: integer; //declare the parameter-result
    begin
    if FindColor(x,y,12345,1,1,1,1) then  //its making use of its output result (the boolean) for the conditional statement
      Mouse(x,y,5,5,true); //So after u called the function, u can just use the parameter result (x,y) in another function as long as its called within the same procedure as u called FindColor (unless u declare x,y globally which is not recommended)

    writeln(toStr(x)+','+toStr(y)); //see how i can just freely use the parameter result anytime (within the same procedure) again?
    end;
    Just an example though, u shd always use tolerance in ur rs scripts.

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

    Default

    Quote Originally Posted by riwu View Post
    It is impossible for a function to return 2 results the conventional way. i.e. no such thing as function abc: boolean and string;
    Hence to get around it, ppl have to load the result into the parameter.
    I concur..

    Simba Code:
    type Results = record
      ReturnValue: Boolean;
      X: Integer;
      Y: String;
    end;

    Function ReturnTwoValues: Results;
    begin
      Result.ReturnValue:= True;
      Result.X:= 5;
      Result.Y:= 'SomeString';
    end;

    Function ReturnMostValues: TVariantArray;
    begin
      SetLength(Result, 3);
      Result[0]:= True;
      Result[1]:= 5;
      Result[2]:= 'SomeString';
    end;

    begin
      WriteLn(ReturnTwoValues);
      WriteLn(ReturnMostValues);
    end.


    Compiled successfully in 16 ms.
    (1, 5, 'SomeString')
    [True, 5, 'SomeString']
    Successfully executed.
    I am Ggzz..
    Hackintosher

  20. #20
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    A simpler example would be FindColor(x,y,12345,1,1,1,1):boolean;
    So u would usually use the function by:
    Simba Code:
    procedure abc;
    var
      x,y: integer; //declare the parameter-result
    begin
    if FindColor(x,y,12345,1,1,1,1) then  //its making use of its output result (the boolean) for the conditional statement
      Mouse(x,y,5,5,true); //So after u called the function, u can just use the parameter result (x,y) in another function as long as its called within the same procedure as u called FindColor (unless u declare x,y globally which is not recommended)

    writeln(toStr(x)+','+toStr(y)); //see how i can just freely use the parameter result anytime (within the same procedure) again?
    end;
    Just an example though, u shd always use tolerance in ur rs scripts.
    I know about tolerance and tpa and stuff. Also in findcolor wouldn't you have to add "var" inside the paranthesis? And how do you declare a parameter and a parameter-result at the same time?
    And Brandon I am not too comfortable with types and records.
    Thanks for all your answers. This has cleared up a lot.
    -Crit
    I want to make a working script. Lets hope i can be bothered anytime soon

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

    Default

    Quote Originally Posted by Crit Boy View Post
    I know about tolerance and tpa and stuff. Also in findcolor wouldn't you have to add "var" inside the paranthesis? And how do you declare a parameter and a parameter-result at the same time?
    And Brandon I am not too comfortable with types and records.
    Thanks for all your answers. This has cleared up a lot.
    -Crit
    u only add "var" when u are creating the function, im calling an existing function so the parameter is just x and y.
    when i use the term "parameter-result" i just mean the "var parameter", not really too sure what its formally called. U dont have to declare output results. (unless u want to make a new variable to store the output result, like 'Total' in the previous examples)

  22. #22
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    u only add "var" when u are creating the function, im calling an existing function so the parameter is just x and y.
    when i use the term "parameter-result" i just mean the "var parameter", not really too sure what its formally called. U dont have to declare output results. (unless u want to make a new variable to store the output result, like 'Total' in the previous examples)
    Sorry of course... Wow I'm a derp. For the second question I mean what of you need two results but also want to call a function's or procedure's parameters in the main loop. Does it work? The answer is not too important as you have fully answered my original question. Tyvm
    -Crit
    I want to make a working script. Lets hope i can be bothered anytime soon

  23. #23
    Join Date
    Oct 2011
    Location
    UK
    Posts
    1,322
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Crit Boy View Post
    Sorry of course... Wow I'm a derp. For the second question I mean what of you need two results but also want to call a function's or procedure's parameters in the main loop. Does it work? The answer is not too important as you have fully answered my original question. Tyvm
    -Crit
    Yes, I'll show you what adding Var in the parameter does:
    Say we have a function like this:
    Simba Code:
    program new;
    Var
      x, y, z : integer;

    Function AddTheseNumbers(Num1, Num2 : integer) : integer;
    begin

      Result := Num1 + Num2;

    end;

    begin

      x := 2;
      y := 3;
      z := AddTheseNumbers(x, y);
      WriteLn('x = '+IntToStr(x)+' y = '+IntToStr(y) + ' z = '+IntToStr(z));

    end.
    As you would expect you get this:
    Code:
    x = 2 y = 3 z = 5
    But what about if we want to set the numbers to 0 once we have added them:
    Simba Code:
    program new;
    Var
      x, y, z : integer;

    Function AddTheseNumbers(Num1, Num2 : integer) : integer;
    begin

      Result := Num1 + Num2;
      Num1 := 0;
      Num2 := 0;

    end;

    begin

      x := 2;
      y := 3;
      z := AddTheseNumbers(x, y);
      WriteLn('x = '+IntToStr(x)+' y = '+IntToStr(y) + ' z = '+IntToStr(z));

    end.
    This gives out the exact same thing:
    Code:
    x = 2 y = 3 z = 5
    We have to tell the function that it is allowed to change the values stores in Num1 and Num2, we do this by adding Var before we declare them, like this:
    Simba Code:
    Function AddTheseNumbers(Var Num1, Num2 : integer) : integer;
    Then when we run it:
    Code:
    x = 0 y = 0 z = 5
    Because they were Variables (not Constants) the values in them could be changed in the function.

    A good example for when this is used is in FindColorSpiralTolerance, you could look at that

  24. #24
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by putonajonny View Post
    We have to tell the function that it is allowed to change the values stores in Num1 and Num2, we do this by adding Var before we declare them, like this:
    Simba Code:
    Function AddTheseNumbers(Var Num1, Num2 : integer) : integer;
    Then when we run it:
    Code:
    x = 0 y = 0 z = 5
    Because they were Variables (not Constants) the values in them could be changed in the function.

    A good example for when this is used is in FindColorSpiralTolerance, you could look at that
    Ah ok I get this now. Why if you want the function to be able to change some I the values inside the parameter but not all of them? Would you just not change them inside the function?
    Thanks anyway for your detailed answer!
    -Crit
    Last edited by Crit; 06-30-2012 at 11:44 AM.
    I want to make a working script. Lets hope i can be bothered anytime soon

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

    Default

    Quote Originally Posted by Crit Boy View Post
    Ah ok I get this now. Why if you want the function to be able to change some I the values inside the parameter but not all of them? Would you just not change them inside the function?
    Thanks anyway for your detailed answer!
    -Crit
    Any value that u didnt put a var in front will not be changed. i.e.
    function FindColor(var x,y: integer; color, blabla: integer):boolean;
    Only the value x,y will be dynamic (depending on what u assign them to in the function), and the rest that doesn't have "var" will just be parameters (which u decide what are they when u call the function)

Page 1 of 2 12 LastLast

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
  •