- Home /
This question was
closed Oct 26, 2013 at 11:29 PM by
fafase for the following reason:
Question is off-topic or not relevant
Question by
Shadowraix · Oct 26, 2013 at 11:27 PM ·
variablesclassesscopeconstructors
Variables having 2 values within a Class?
Alright, so I have been watching a tutorial series and I was learning about how classes and constructors work. This is the example.
function Update()
{
var crazyBot = Person("crazyBot")
var horseMan = Person("horseMan")
crazyBot.TeamUp(horseMan)
}
class Person
{
var name;
function Person(n : String)
{
name = n;
}
function TeamUp(p : Person)
{
print(name + "teamed up with" + p.name + "!");
}
}
My main focus is the print line. It references to the variable "name" twice by directly calling it with just name then using p.name. As a result of this code you get "crazyBot teamed up with horseMan!" How is the name variable acting as if it has 2 values? Also, how would you adapt this if you wanted to use 3 or more values?
Comment
Your question does not make any sense. You are wondering why your program is working properly.
name is for the object so it is crazy bot, p.name is the name of the object you are passing which is horseman.