Search Unity

Unity Glossary of Terms

Discussion in 'Scripting' started by Andy, Jan 9, 2007.

  1. Andy

    Andy

    Joined:
    Nov 5, 2006
    Posts:
    50
    I am new to programming but am making progress with JavaScript. There are some words which I and perhaps others would like to get a better understanding of. I invite those with more knowledge to help us out by filling in the definitions. Thanks, Andy

    Method-
    Runtime Classes-
    MonoBehaviour-
    Enumerations-
    Inherited from-
    Member Variables-
    Global Variables-
    Private-
    Public-
    derives from-
    Class-
    Class Member-
    Class Functions-
    Class Variables-
    Constructors-
     
  2. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    Here's my attempt, scribbling out some thoughts on my lunch break. My use of terminology might not be totally consistent because different languages use different words to describe the same things. For example, functions, methods and events are essentially the same thing. Variables and properties are conceptually the same thing (even though they work differently internally).

    I should probably define one other term I use: object. An object isn't (necessarily) a GameObject in this case - rather it's a particular instance of a class or script. If you create a GameObject which has a special Missile script on it, the Missile script is a separate object in its own right, and if you create multiple missiles, you have multiple Missile script objects.

    Method - a function attached to an object of a class. This function has access to any of the other methods and member variables of the class. All of your functions in Javascript in Unity are methods as you can't create standalone functions in Unity.

    Runtime classes - I guess this means classes which are relevant to the game rather than to the editor. It's not a term that means something specific to me.

    MonoBehaviour - this is the class that all (normal) Unity scripts are derived from. It gives you easy access to common components on the same GameObject as the script, and it also provides as set of events (such as Update) which are automatically called on your script. See the MonoBehaviour documentation for more information.

    Enumerations - an enumeration is a group of names which refer to values. For example:

    Code (csharp):
    1. enum AIState
    2. {
    3.     Waiting = 0,
    4.     Chasing = 1,
    5.     Fleeing = 2
    6. }
    These names can be used in your scripts in the form AIState.Waiting instead of having to use arbitrary numbers like '0'. You can also omit the values from the above example (remove the '= 0' bit) to have it automatically assign successive values starting from zero.

    Inherited from - in Unity, all classes have a base class which gives them some of their properties and methods. Your scripts are derived from the base class MonoBehaviour (as mentioned above), and they inherit methods (such as GetComponent), events (Update) and properties (enabled) from it.

    Member variables - these a variables which are attached to an object of a class. In Javascript, these are variables declared outside of functions. There are also properties, which behave similarly to member variables, but which might also have a function attached to them to handle the data in a particular way. Javascript doesn't have properties, but the Unity API does - anything (such as 'enabled') which lets you get or set a value is a property.

    Global variables - variables which are accessible from all functions. There are no true global variables in Unity's languages, but you can simulate them by having a script on an object which has easily accessible member variables. See this script for a way of doing this.

    Private - member variables or functions which are only accessible from the class they belong to. In Unity's Javascript, you use the private keyword to stop member variables from appearing in the inspector, as well as to prevent other scripts from tampering with these values.

    Public - member variables or functions which are accessible to any class. In C# and Boo, you have to explicitly say 'public' to make member variables appear in the inspector. In Javascript, all member variables are public automatically.

    Derives from - see inherited from, above.

    Class - a script file defines a class in Unity. For example, the file MyScript.js defines a class called MyScript.

    Class member - any method, variable or anything else belonging to a class.

    Class functions, class variables - whereas normal functions can only access other functions and variables attached to their own object (unless they have a reference to something else), class functions and variables are shared between all objects of a particular class. If one object changes a class variable, and another one reads its value, it will see the value set by the other object instead of having its own personal copy.

    Constructors - you don't generally need to worry about constructors in Unity. Their job is to initialise all the members of an object in an appropriate way before anything gets a chance to call functions on it. In Unity, this functionality is handled by implementing the Awake or Start events.

    Hope that makes at least a little sense. I can probably explain in more detail if you want more clarification. :)
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I should point out that these are often referred to as static variables and functions, too.
     
  4. Andy

    Andy

    Joined:
    Nov 5, 2006
    Posts:
    50
    Thank you for the clarifications. I will take some time and chew these over, I'm sure I'll have more questions in the future.

    thanks, Andy