- Home /
Using bool function with parameters
Dear Community,
I'm activating a function BadWordFilter after pressing a Button and I give a parameter which is a string. (First Script)
In the Second Script I'm checking if the player Name contains a bed word and return a bool. Now back in the First Script I would like to ask if the returned bool is true, if it's true then Start a Coroutine and if not then do that what is under else-statement.
Problem is that it says in the if-statement I can't use a == operator. So how do I check propetly the returned bool in the if-statement? I would be happy for any code advices.
Fist Code:
public void OnButtonClicked()
{
string newName = inputName.text.ToLower();
ListAndFilterForBadWords laffbw = new ListAndFilterForBadWords();
laffbw.BadWordFilter(newName);
if (laffbw.BadWordFilter == true)
{
StartCoroutine("SetWarning");
}
else
{
StartCoroutine("SetPlayerName");
}
badWordWarning.SetActive(true);
}
Second Code:
public bool BadWordFilter (string playersNewName)
{
foreach(string word in words)
{
if (playersNewName.Contains(word))
{
return true;
}
}
return false;
}
Answer by fafase · Sep 27, 2017 at 06:50 AM
public void OnButtonClicked()
{
string newName = inputName.text.ToLower();
ListAndFilterForBadWords laffbw = new ListAndFilterForBadWords();
if (laffbw.BadWordFilter(newName) == true)
{
StartCoroutine("SetWarning");
}
else
{
StartCoroutine("SetPlayerName");
}
badWordWarning.SetActive(true);
}
I removed the first call for BadWordFilter as you were not storing the result. Then the second call was missing the parameter list.
Your answer
Follow this Question
Related Questions
Why doesn't my if statement work? 1 Answer
check guitexture 2 Answers
Time is not stopping 2 Answers
Trying to create a function that returns a bool 2 Answers
Scavenger Hunt List Bools Question 1 Answer