Search Unity

Visual Studio Code Explanation is wrong/has a typo

Discussion in 'Editor & General Support' started by ceasar_jl, Aug 21, 2018.

  1. ceasar_jl

    ceasar_jl

    Joined:
    Apr 15, 2017
    Posts:
    3
    So in the unity documentation about Random.Range it says "Returns a random integer number between min [inclusive] and max [exclusive] (Read Only)."

    Through my testing this has proven to be true, but in Microsoft Visual Studio, there is a little tip kind of thing that explains what a bit of code does, it says "Returns a random float number between min[inclusive] and max[inclusive] (Read Only)."

    Which is wrong, i don't know if this is a problem with unity or a problem with Visual Studio but i thought you'd want to know.

    upload_2018-8-21_19-44-34.png
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Random.Range has one overload:
    The original that accepts integers, and one that accepts floats.

    Notice the "1 of 2" section of the tooltip. You can use the up/down arrow keys to cycle through each overload a method has.
    Note that this doesn't physically change which version of the method you're using; it just shows a preview. You will have to supply the required parameters to use the correct version you wish.

    For instance, if you do this:
    Random.Range(1, 10);

    You will get only integers between 1 and 10 returned (no decimals).

    And if you do this:
    Random.Range(1f, 10f);

    The "f" explicitly states that these parameters are floats, which allows it to return any number between 1 and 10 including decimals.

    Method overloading is just a way to organize code, and all you have to do to create an overloaded method is to give it the same name as an existing method, but have at least one difference with parameters.
    For example:
    Code (CSharp):
    1. void MyMethod() {
    2.    //Do stuff...
    3. }
    4.  
    5. void MyMethod(int x) {
    6.    //Do stuff...
    7. }
    8.  
    9. void MyMethod(string x) {
    10.    //Do stuff...
    11. }
    12.  
    13. void MyMethod(int x, string y) {
    14.    //Do stuff...
    15. }
    16.  
    17. void MyMethod(string x, int y) {
    18.    //Do stuff...
    19. }
    20.  
    21. void MyMethod(int x, string y, string z) {
    22.    //Do stuff...
    23. }
    24.  
    25. void MyMethod(int x, string y, float z) {
    26.    //Do stuff...
    27. }
    Etc.

    All of these methods are valid even though they all have the same name. Because the parameters are unique for each one, the compiler has a way of identifying which version is being called based on which parameters are inputted.
     
    Last edited: Aug 21, 2018
    Joe-Censored likes this.