Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Am I misunderstanding the MonoDevelop IDE?

Discussion in 'External Tools' started by nswayze, Dec 20, 2017.

  1. nswayze

    nswayze

    Joined:
    Nov 17, 2016
    Posts:
    17
    I'm still new to the world of scripting and this is a noob question but why does the MonoDevelop autocomplete or helper (or what ever it's called) display some confusing suggestions?

    For example I wanted to play with a lights intensity but I wasn't sure of it's syntax so I figured the helper would give me an idea.



    but above it's talking about { get; set; } when the correct syntax I was looking for was

    Code (CSharp):
    1. variable.intensity = (number);
    (or in my case myNewLight.intensity = 4; )

    Is there something that I'm just not understanding about this helper?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    6,970
    The autocomplete (sometimes called Code Completion, Code Assist, or colloquially as IntelliSense as it is named in Visual Studio) is showing how that particular variable is defined, not how it is used.

    In this case the public float intensity { get; set; } is referring to the fact that it is public (anything can access it), a float (a floating point numerical value), and defined as a getter setter. For your own code you're probably just going to see something like public float foo; by itself, or potentially public float foo = 1.0f; if you have a default value. So what is a getter setter?

    You don't necessarily need to understand what a getter setter is, but basically that's saying you can get and set that value. In some other cases you may see a variable defined as:

    public float foo { get; }

    or

    public float bar { set; }

    in which case you can only read foo and set bar.

    Getter setters are useful for exposing values that are otherwise private, or to allow some control over those values when they are set or read, i.e.: if you have a value you know must be in some range you can clamp it to those values on set. Or if you want some public variable to be defined internally by multiple variables or internal states, like:

    public bool running { get { return _turnedOn && _hasPower }; }


    That returns true only if it both has power and is turned on.

    They're like functions, but you can have a single getter setter "variable" instead of separate SetFoo(value) and GetFoo() functions for simplicity. In this case Unity is using a getter setter because the c# Light class is a wrapper for an internal c++ class and setting or getting the variables on it effectively calls a function into the c++ code. That additional code is generated elsewhere and hidden from the user.
     
    Last edited: Dec 20, 2017
    nswayze likes this.
  3. nswayze

    nswayze

    Joined:
    Nov 17, 2016
    Posts:
    17
    Thanks for your well thought out response. The get/set thing was confusing but this has really made it a lot clearer for me.

    Do you happen to know if there's any 3rd party tools or anything out there which acts like the IntelliSense feature but instead shows examples of usage? basically like the api documentation. Without having to visit the page?

    Thanks again.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    6,970
    Nope. My programming tool of choice is SublimeText which doesn't even have any kind of IntelliSense, so I'm a terrible person to ask.
     
    nswayze likes this.