A list of questions from a complete beginner...

Hello everyone,

I’ve recently started how to code on my own and I have some questions I can’t find answers to in my book. It’d be cool if you guys could help otherwise I’ll probably find it out eventually but there are certain things I’d like to learn right now :). Links with the answers would be nice if writing everything would take too long.

  1. What’s the advantage of using the private function? Isn’t it better to be able to see all the commands in the console?

  2. I thought all statements needed to end with a semi-colon. Why is that sometimes you’ll get things like this:

    void Start()
    {
        characterCombat = CharacterCombat.Instance;
    }
    public void Initialize()
    {
        //startTime = Time.realtimeSinceStartup;
        Show();
    }

Void ends with () not with a ;. So I take it that void () isn’t a statement. What is it then?

  1. How do I integrate the source code to Unity? The programmer that joined disappeared and I can’t reach him although I’ve tried many times.

When I download the zip file from bit bucket I get the following:

I tried to open the source code in Unity but I can’t find out how. Do I need to integrate every single Asset individually in Unity?

  1. So I understand I need to declare a variable before using it. In the following case:
public class Clock : MonoBehaviour
{
    public SpriteRenderer SpriteRenderer;
    public Animator Animator;

    //private float startTime;
    private CharacterCombat characterCombat;
    private Animator thisAnimator;

    void Start()
    {
        characterCombat = CharacterCombat.Instance;
    }
    public void Initialize()
    {
        //startTime = Time.realtimeSinceStartup;
        Show();

Is "public SpriteRenderer SpriteRenderer; the part where I declare a variable? According to my book, a variable begins with a lowercase so I guess in this case it’s a class, right? Why is SpriteRenderer showing up twice? I don’t understand.

  1. Why is it that characterCombat doesn’t have a dot in between the two words and the other CharacterCombat.Instance does? Why isn’t there a . between Character and Combat? My book says that’s “dot syntax”…?

  2. Why use float here and not integer (int)? :

   public void Deinitialize()
    {
        //float elapsedTime = Time.realtimeSinceStartup - startTime;
        //Debug.Log(string.Format("Elapsed Time: {0}s", elapsedTime));
        Invoke("Hide", 1.0f);
  1. My book keep talking about “methods”, so googled the term and tried to find more information about it:

Where would the method be in there:

public class Clock : MonoBehaviour
{
    public SpriteRenderer SpriteRenderer;
    public Animator Animator;

    //private float startTime;
    private CharacterCombat characterCombat;
    private Animator thisAnimator;

    void Start()
    {
        characterCombat = CharacterCombat.Instance;
    }
    public void Initialize()
    {
        //startTime = Time.realtimeSinceStartup;
        Show();

The statements are the lines ending with ;. A method is a code block containing a series of statements. So would line 2 to 13 be a method since it’s a code block containing statements?

According to my book:

So are the lines ending with () methods then? I understand a method refers to some lines of code. It’s sort of a substitute for a group of lines of code. Does that mean that Void Start () refers to some lines of code already written somewhere in the script? Or is it simply that what is between { } are methods?

Ok, that’s enough questions for now. I’m trying to pick up where the programmer left off and it’s very confusing at first.

Thanks for reading,

Z.

It allows you to control encapsulation of members. If code outside the scope of the class can access it or not. As you are new to this, the concept and use of encapsulation may be a little above your head at this moment.

That is a function/method declaration.

Note here, statements don’t always end with a semi-colon:

Open that project, or integrate into your project?

Opening is easy, just have unity open the folder that this is contained in.

Integrating can be complicated. Everything in the ‘Assets’ folder would have to be copied into your project’s ‘Assets’ folder, that’s fine and easy. But there might be ProjectSettings that are necessary and conflict with your existing ProjectSettings. So copying the directly may break your current project… you’d have to compare the project settings and find a mix of the two that works for you.

Yes, the variable is declared there.

It being uppercase is because YOU declared it with an uppercase. Just because something is uppercase doesn’t make it a class, it’s just that it is common that people stick to uppercase for declaring the class/type, and lowercase the variable referencing the object of that class/type.

This is merely individual taste.

Personally I prefer my class level members to start all uppercase (and it’s actually the msdn standard as well), unless private, in which case my class level fields start with a ‘_’ followed by lowercase (not msdn standard).

A variable/member can be made up of multiple words. The compiler does not recognize words in particular… it’s just a random jumble of letters and digits to it. A member name is broken when followed by a space, period, or other symbol. So people will use what is called ‘camel case’ to write multi-word names, like ‘characterCombat’ or ‘theCheeseIsYellow’.

The dot/period/. on the other hand is the symbol that commands accessing the member. May it be accessing its sub-members, or its sub-namespace. ‘CharacterCombat.Instance’ is accessing a static property of ‘CharacterCombat’ named ‘Instance’.

Because float can have fractional values, and the method ‘Invoke’ takes in a duration in seconds, of which you might want fractional seconds.

Method is a synonym for ‘function’ (sort of).

Technically a method is a ‘function’ and/or ‘routine’.

Functions by definition return something, but you can have functions that return nothing (void)… which technically isn’t a function (by the traditional definition). So the word ‘method’ is used to describe both functions and routines (where a routine is just a command with no return, void).

Thing is, it’s become common to refer to both routines and functions as just functions (especially with languages like javascript straight up using the word ‘function’ in declaring functions). But traditionally speaking, from mathematics, where the name is taken. A function is “an expression who for any given input has a single output”, so in algebra you may test if an expression is functional. Where something like f(x) = x^2 is functional, and f(x) = sqrt(x) is not.

Now a days, they’re synonomous. Method/function/routine all pretty much mean the same thing. Some will even argue that C# routines are functions that return void… but they don’t return anything! The void sits in the place where the return type is… that doesn’t mean it returns anything. Where as in VB.Net, you actually explicitly change the name of the method:

Public Function Foo() As Boolean
    Return True
End Function

Public Sub Bar()

End Sub

the parts like:

void Start()
{
    ...
}

and

void Initialize()
{
    ...
}

These are methods.

A method is broken down into multiple parts, read this article for a full break down:

You have:
access modifier
return type
name
parameters
body

1 Like

Hello lordofduct,

You’re right, it is. :slight_smile: I haven’t read about that yet. I don’t know what a member is yet.

So all lines ending with () are function declarations, right?

Opening the project.

So if I understand correctly, I need to open the folder containing the project with Unity.

The folder containing the project should be this one:

as it contains this:

It seems empty however when I open it. It should be as the folder is 100MB+ so there’s definitely something there. Or is it the “ProjectSettings” that I need to open?

Yes I understand but it’s a good habit to take because it make things easier to understand according to my book.

So in dot syntax, what comes after the . is what is being accessed.

Ahh! Ok! If I had stuck to integer, I wouldn’t have access to fractions of a second then, only to whole seconds.

Ok so what would normally come in between the ( ) would be the parameters.

There are two types of methods:

  1. So routines are whenever you have void ().
  2. Functions which are not void (). They return something.

In your example:
void Start ()
and
void Initialize ()

you’re saying they are methods but if you wanted you could say they are routines if you wanted to be more precise from what I understand.

I tried to understand the “method” article but it’s over my head at the moment. I have a better understanding now though.

A member is any variable, function, property, event, etc declared in the scope of a class/type. It’s a “member” of that type. It’s a generalized word.

Nope… it might end with (int arg1) or some other combination of parameters/arguments.

Also there are all sorts of statements that use parens, if statements, loops, etc.

No, don’t open the ProjectSettings.

That folder hierarchy is the structure of a unity project:

MyProject
->Assets
->Library
->ProjectSettings

If you open MyProject it should have the project. If nothing is showing, it may be malformed.

Yes being consistent with your naming system does make it easier to read. But that doesn’t mean it makes it a class or whatever… it just means you weren’t consistent.

What’s before the dot is what’s being accessed, what is after is the member of that what that is being accessed.

yep

Yep

Yep.

And this would be a function:

int Foo()
{
    return 5;
}

But as I said, the names today are fairly interchangable.

Here on the forums everyone would refer to both as ‘functions’, because slang.