Search Unity

LoginAccountWWW.text != ''Success" Why?

Discussion in 'Scripting' started by Slyrfecso1, Nov 17, 2015.

  1. Slyrfecso1

    Slyrfecso1

    Joined:
    Jul 16, 2012
    Posts:
    100
    Hi,

    I have found a problem in MySQL Login.
    I got back "Success" from server, and I see this in Debug Console, but:
    if(LogText == "Success") {}
    nothing happening.
    I don't now why, but maybe "LogText" is different?
    Need I convert or encode to any other format?
    I'm using Unity 5.3.0f1.

    Code (CSharp):
    1. IEnumerator LoginAccount (){
    2.  
    3.         WWWForm Form = new WWWForm ();
    4.         Form.AddField ("User", userLog);
    5.         Form.AddField ("Password", passwordLog);
    6.         WWW LoginAccountWWW = new WWW (LoginUrl, Form);
    7.         yield return LoginAccountWWW;
    8.         if (LoginAccountWWW.error != null) {
    9.             Debug.LogError("Hiba a belépés során!");
    10.         } else {
    11.             LogText = LoginAccountWWW.text;
    12.             Debug.Log (LogText);
    13.  
    14.             if (LogText == "Success")
    15.             {
    16.                 Application.LoadLevel("Terberendezo_v1");
    17.             }
    18.  
    19.  
    20. //            string[] LogTextSplit = LogText.Split(':');
    21. //            if (LogTextSplit[0] == "0")
    22. //                {
    23. //                if (LogTextSplit[1] == "Success")
    24. //                    {
    25. //                    Application.LoadLevel("...");
    26. //                    }
    27. //            }
    28. //            else {
    29. //                if (LogTextSplit[1] == "Success")
    30. //                {
    31. //                    Debug.Log ("Nincs...")
    32. //                }
    33. //
    34. //            }
    35.  
    36.  
    37.  
    38.         }
    39.  
    40.     }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    4,872
    The text might be the HTML payload source of your website.

    It also might be prefaced by HTML decorators that are invisible on the website.

    Perhaps you want instead:

    Code (csharp):
    1. if(LogText.Contains( "Success")) ... etc.
     
    Nigey likes this.
  3. Slyrfecso1

    Slyrfecso1

    Joined:
    Jul 16, 2012
    Posts:
    100
    Thank you so much, it is working well.
    Have a nice day.
     
  4. Slyrfecso1

    Slyrfecso1

    Joined:
    Jul 16, 2012
    Posts:
    100
    How can I use Contains with If together?
    I got back more information with separator "User:Fullname:Email:Succes" and If [3] = success, then I can load the next scene.


    Code (CSharp):
    1. string GetDataValue(string data, string index)
    2.     {
    3.         string value = data.Substring(data.IndexOf(index)+index.Length);
    4.         if (value.Contains(":"))value = value.Remove(value.IndexOf(":"));
    5.         return value;
    6.     }
    How can I use this in "If"?
    print(GetDataValue(data[3],""));
     
    Last edited: Nov 21, 2015
  5. Slyrfecso1

    Slyrfecso1

    Joined:
    Jul 16, 2012
    Posts:
    100
    Hi!

    After 2 years I have updated my Unity editor to the latest 2017.01.0f3.
    I think something had been changed in Editor, because my login script failed.
    The MySQL server sent back some information, but it is not enough to solving.
    The script is working in older version or in Mobile App, therefor PHPs, Forms, Server, Internet are good.

    Code (CSharp):
    1. WWW LoginAccountWWW = new WWW (LoginUrl, Form);
    2.         yield return LoginAccountWWW;
    3.         if (LoginAccountWWW.error != null) {
    4.             Debug.LogError("Failed under login!");
    5.             label5=true;
    6.         } else {
    7.             string LogText = LoginAccountWWW.text;
    8.             //Debug.Log (LogText);

    This is the console message:



    If I change "LoginAccountWWW.error != null" to "LoginAccountWWW.error == null"
    then I can get out the error, but it is not solution.

    Any idea?
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    4,872
    In your if statement try querying

    Code (csharp):
    1. if (!string.IsNullOrEmpty( LoginAccountWWW.error))
    instead.
     
unityunity