I have the code below witch ask in a Mysql databae if a player exist.
The user.php returns a string “yes” or “no” depending if player exist or no;
The problem is that the code in the line 18, prints normally the word (yes or no), but the next two if statements can not make the comparison and and my code cannot pass through those statements.
Simply the code from line 21 to 31 is like it never existed.
Any idea ?
Private string checkName= "user";
Private string exist;
public string GetNameUrl = "http://www.url.com/user.php";
IEnumerator check4NameInServer(string checkName)
{
WWWForm form = new WWWForm();
form.AddField("username",checkName);
WWW www = new WWW(GetNameUrl,form);
yield return www;
if(www.text == "") {
updateMessageBox ("You Are Not Connected. \nError:" + www.error);
}else {
exist = www.text;
print("-> "+exist);
}
if(exist.Equals("yes")){
print ("1->pass from here");
}else if(exist.Equals("no")){
print ("2->pass from here");
}
if(exist == "yes")){
print ("1->pass from here");
}else if(exist == "no"){
print ("2->pass from here");
}
}
Are you sure there is no break line or a space after the response? It would seem the same in the output, but the comparison won’t work. Can you say what the result for print(“'” + exist + “'”); is?
For some very crazy reason, when i copy the <yes> text from the console output (the output of the line 18) and paste it on the csharp equation of the code, line 21, the it worked for me. now i am thinking that is a problem with the encoding.
But i still have the problem because i have many texts that i have to control with if statements.
Seems so. I’d make sure to use the same encoding (ASCII or UTF8) on both ends.
You could also try to get the bytes array from the stream (WWW.bytes) and convert that to an encoded string to see if that helps.
i will try that soon, but now i notice that and other if statements of string, does not work, which are simple string not from WWW. now i will reinstall monodevelop and unity.