- Home /
cannot make a list with the word hello in it
I am trying to make a list of greetings. All of them work as intended except for "hello". I have moved it around but i still get no match. I do not know what is going on.` using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq;
public class SARAH : MonoBehaviour {
int tgt = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void Processtags(List<string> tags)
{
List<string> greetingoffencenoun = new List<string>();
greetingoffencenoun.Add("greeting");
greetingoffencenoun.Add("offencenoun");
if (tags.SequenceEqual(greetingoffencenoun))
{
print("we haz a mach!!");
}
}
public void GetText(string text)
{
string[] greetingz = new string[]{ "hi", "hello", "howdy", "ello" };
string[] offencenouns = new string[]{ "idiot", "moron", "simpleton", "egghead" };
tgt = 0;
List<string> tags = new List<string>();
foreach (string x in greetingz)
{
if (text.Contains(x))
{
tags.Add("greeting");
tgt += 1;
//print(greetings[UnityEngine.Random.Range(0, greetings.Length)]);
}
}
foreach (string x in offencenouns)
{
if (text.Contains(x))
{
tags.Add("offencenoun");
tgt += 1;
}
}
if (tgt == 2)
{
Processtags(tags);
}
}
} `
I guess this could be the problem: hello
contains hello
and ello
(line 42) so you get 2x tgt+=1
in line46 and probably end up with tgt == 3
and Processtags
is never called.
Answer by shinevision · Jan 25, 2018 at 12:17 AM
Mmm, Strange...
Maybe its because you also have "ello"? because ello is inside hello?
Try removing ello and try the script again, if the problem is gone, then thats thje problem :)
Your answer
Follow this Question
Related Questions
Confused about copying Lists! 1 Answer
Multiple Cars not working 1 Answer
AI patrol not working 0 Answers
Trouble with removing items from a list by string 0 Answers
How can I get just one componente, or except one, from a list? (string.Join) 0 Answers