[SOLVED] Change Pawn Name

Started by O Negative, December 31, 2018, 09:52:39 PM

Previous topic - Next topic

O Negative

How do I go about changing a human pawn's last name in C#?

I have successfully changed a pawn's name to the same name another pawn has, but I can't seem to use strings to do what I want to accomplish. Any ideas?


String s = "O Negative";
pawn.Name = pawn2.Name; // This works!
pawn.Name = s; // This does NOT work!


I am essentially looking to give child pawns the ability to inherit last names from their parents, for anyone who is curious. I have a few methods written to parse the pawn.Name.ToString() string, and create a new string with the child pawn's first name and the parent pawn's last name; it's just a matter of applying that string to the name.

Razuhl

No need to parse. The named pawns have a name object of type NameTriple which has a string field for the surname. This should work if both are named and you would need to implement a version that allows pawnTo to have a name of type NameSingle if you want to support unnamed pawns.


NameTriple nFrom = pawnFrom.Name as NameTriple;
NameTriple nTo = pawnTo.Name as NameTriple;
if ( nFrom  != null && nTo != null ) {
pawnTo.Name = new NameTriple(nTo.First,nTo.Nick,nFrom.Last);
}

O Negative

Thank you for the information! :D