- Home /
How is this always the same outcome?? Caution: contains sex! ;)
Hey Guys, I'm running in to a weird problem that I'm sure is a simple solution but for some reason when I always get the "NoGender = 0" value returned in my enum even tho all the other variables in my Sex class return appropriately. Have a look at the constructor then see the output below:
public enum Gender {
NoGender = 0,
Male = 1,
Female = 2,
COUNT = 3
}
public class Sex {
public Gender gender;
public string name;
public string possesiveName;
public string thirdPersonName;
public string youngName;
public string grownName;
public Vector3 sexScale;
public int[] hairIndexes;
public Sex(Gender gender) {
if(gender == SexData.Gender.Male){
gender = SexData.Gender.Male;
name = "Male";
possesiveName = "his";
thirdPersonName = "he";
youngName = "boy";
grownName = "man";
}
else if(gender == SexData.Gender.Female){
gender = SexData.Gender.Female;
name = "Female";
possesiveName = "her";
thirdPersonName = "she";
youngName = "girl";
grownName = "woman";
sexScale = new Vector3(.8f, .9f, .8f);
}
else{
gender = SexData.Gender.NoGender;
name = "No Gender";
}
}
}
Meanwhile; In another script....
int temp = UnityEngine.Random.Range( (int)SexData.Gender.Male, (int)SexData.Gender.COUNT );
characterSex = new SexData.Sex((SexData.Gender)temp);
Debug.Log(characterSex.gender + " = " + (int)characterSex.gender + " aka " + characterSex.name);
Will always output in the console: "NoGender = 0 aka Female" or "NoGender = 0 aka Male" In short, characterSex.gender always returns the same while characterSex.name (set in the constructor) returns appropriately!! I'm lost, thanks for the help!
What's the difference between SexData.Gender
and Gender
? Assu$$anonymous$$g they're they same, your random range is in the exclusive range (1,3(, so it is indeed quite suprising you get "NoGender = 0"...
Yeah, they're the same. SexData is just the class that my Sex class is located in
Answer by Jamora · Sep 17, 2013 at 05:34 PM
You're assigning to the gender variable passed as a parameter.
You need
if(gender == SexData.Gender.Male){
this.gender = SexData.Gender.Male;
gah!! i can't believe it! I think I'll change the passed variable name to "g" or something less dumb.
thanks for the help!
That's why all my function parameters start with a small "a" (for argument) like (Gender aGender) ;)