- Home /
script ignoring variables when assigning them in the hierarchy
Problem
So today I was working on an age system, to improve my knowledge of JavaScript, all was going well till I wanted to have an output of age... It works okay, no bugs or anything like that; the only problem is, the variables I input from the hierarchy does not change the personsAge final output, like the sums are done perfectly - if I change the sum inside the script it comes out the way it should, but if I want to change the the variable dateYear it does not update the sum inside of the script, so it comes up with the answer that I clarified in the script before (default int number). However it does change the actual year that shows on the input so I know that the dateYear variable is working, just the personsAge variable has something wrong I believe that is stopping any input from the hierarchy.
Code:
Here is my script:
//DateOfBirth
var dateMonth : int = 12;
var dateYear : int = 1996;
var dateDay : int = 31;
var currentYear : int = 2013;
var personsAge : int = (currentYear) - (dateYear);
//Name
var forename : String = "John";
var surename : String = "Doe";
//Define Name and Birth Date and age.
function Start()
{
print ("Name: "+ forename +" "+ surename +" BirthDate: " + dateDay +"/"+ dateMonth +"/"+ dateYear +" Age: "+ personsAge);
}
Additional Info
If the hierarchy settings were the same as the code settings I would have a perfect output, however the variable personsAge seems to dislike the hierarchy.