I made a js file to login on my game, but the IF statement doesn’t work.
And in the debug window i clearly see ‘error’
function Login() {
var form = new WWWForm(); //here you create a new form connection
form.AddField( "myform_hash", hash ); //add your hash code to the field myform_hash, check that this variable name is the same as in PHP file
form.AddField( "myform_nick", formNick );
form.AddField( "myform_pass", formPassword );
var w = WWW("http://sociallife.woelmuis.nl/login.php", form); //here we create a var called 'w' and we sync with our URL and the form
yield w; //we wait for the form to check the PHP file, so our game dont just hang
if (w.error != null) {
print(w.error); //if there is an error, tell us
} else {
answer = w.text;
answer = answer.Replace("<div align=\"center\">","");
answer = answer.Replace(" ", "");
status = answer;
Debug.Log(answer); //here we return the data our PHP told us
if(answer == "error")
{
Debug.Log("loggedin");
}
w.Dispose(); //clear our form in game
}
formNick = ""; //just clean our variables
formPassword = "";
So inside the first Else clause, answer is getting set to “error”. You then print out answer, and it tells you it is indeed “error”. Then you check to see if answer==“error” and it doesn’t go into that If statement.
My guess, considering that you are using PHP is that there’s some kind of whitespace issue. I see that you are deleting spaces, but that might not mean you’re catching all whitespace. Try Debug.Log(“|||” + answer + “|||” ) if it doesn’t say |||error||| then theres some whitespace you need to trim.
If it does come back as |||error||| then we can go from there.
What if it can process the if directive, jumps to the else directive and finds it cannot do what it is supposed to. It would not return anything. Add another step. Perhaps turn the else into an else if and then add the else for if both fail.
I don’t really understand your problem… If you get an error message from your WWW-object, it should say “Error” in your debug window. You yourself has made it so:
if (w.error != null) {
print(w.error); //if there is an error, tell us
}
This just tells me there is something wrong along the way. Either you’re giving the wrong address or a connection could not be made, or something along those lines. But we will never know if you don’t tell us what the error says and on which line, etc.