Variables and Functions {Tutorial Question}

Hi Everybody!

I’m just new with Unity and I was trying lo learn something from a tutorial. This one:

And here’s the script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour {

    int Mario = 5;

	// Use this for initialization
	void Start () {
		Mario = MultiplyByTwo(Mario);
        Debug.Log (Mario);
	}

    int MultiplyByTwo (int Paolo){
        int calcolo;
        calcolo = Paolo * 2;
        return calcolo;
    }
	
	// Update is called once per frame
	void Update () {
		
	}
}

I gave random names to variables just to see if I got the meaning. I’ve also understood everything in the the tutorial except for one thing: I still don’t understand how in this function:

int MultiplyByTwo (int Paolo){
    int calcolo;
    calcolo = Paolo * 2;
    return calcolo;
}

the temporary variable “Paolo” got the value of 5. I’m pretty sure it got it from this variable:

 int Mario = 5;

But how?! The console at the end prints 10 as number.

Thx for your helps.

You define Mario as an int, and assign it 5. You then doubled it to get a new int, 10. When you passed Mario into that method, the VALUE (not the reference name) of Mario (5) is used to assign the internal value of Paolo.

Paolo doesn’t really mean anything, it is created in the function merely to provide a save storage space that the function takes to input.

Paolo has the same status as calcolo really, as far as the function is concerned.