- Home /
Getting a dictionary to recognize a variable string defined elsewhere
So I have 2 dictionaries as of right now:
[HideInInspector] public Dictionary<string,Image> actors = new Dictionary<string,Image>(); // tracks names to sprites
[HideInInspector] public Dictionary<string, Color> actorColors = new Dictionary<string, Color>(); // tracks names to colors... but this is just data, the DialogueUI script has to actually do something with the color
The code my comment is referencing in Dialogue UI looks like this:
if (speakerName.Length > 0) {
// change dialog nameplate text and, if applicable the BG color
nameText.transform.parent.gameObject.SetActive (true);
nameText.text = speakerName;
if (ropework.actorColors.ContainsKey (speakerName)) {
nameText.transform.parent.GetComponent<Image> ().color = ropework.actorColors [speakerName];
}
I have a separate variable which is a string called "playerName" that is clearly showing up when I run the game and works with user input and everything, but for the life of me I cannot get it to register a color or be recognized in any sort of command I write out. My code just refuses to recognize variables as actors but will gladly accept when I write a name straight up such as "Marie" or "Swiss". Any help or direction in this would greatly be appreciated!!!
Hi, have you tried to debug the speakerName variable to see the obtained value?, maybe that have some additional text that don't match you key.
Hi! Yes I have, it simply returns whatever string is present in my dialogue file where the code defines the "speakerName" (anything before this symbol : )