Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

post to server but do not get expected returns

Discussion in 'iOS and tvOS' started by earthcrosser, May 14, 2014.

  1. earthcrosser

    earthcrosser

    Joined:
    Oct 13, 2010
    Posts:
    121
    I developed a game, Alien Checkers, it works perfectly on Android and on the Web, but when I put it on an i-Pad, the multi-player part of the game does not work. I use a form and post information to some php code on a server. In iOS the post goes through but it does not seem to return the expected information. For example I posted my create new user code below. On the iPad I can create a new user, I know because I look at the data base and the new user is there, but you wouldn't know from trying it on the iPad because this line of code:
    Code (csharp):
    1. Application.LoadLevel("onlinesetupmenu");
    is never executed so the game just sits there appearing to do nothing. It is happens like this for my other WWW calls as well. If you want to try the game to see what I'm talking about you can play for free
    alien checkers You see that if you create a new user you should be brought to another screen where you can challenge other players to games.

    I know that was a lot so I'll summarize with these bullets
    On the iPad
    • successfully post data to database
    • do not get the expected returns, so in this case I am not brought to the new level / Screen
    What am I doing wrong here? Once again this is my first try with iOS so I'm hoping it's something simple.


    Here is the full snippet
    Code (csharp):
    1. private IEnumerator CreateNewUserDB(string myUsername, string myPassword, string myEmail ,int myColor){
    2.         var form = new WWWForm();
    3.         form.AddField( "password", "******");
    4.         form.AddField( "username", myUsername);
    5.         form.AddField( "userpassword",myPassword);
    6.         form.AddField ("email",myEmail);
    7.         form.AddField ("color",myColor);
    8.         WWW download = new WWW( "http://www.aliencheckers.com/createnewuser.php",form);
    9.         yield return download;
    10.         if( download.error != null) {
    11.             print( "Error downloading: " + download.error );
    12.         } else {
    13.             PlayerPrefs.SetInt("LoggedIn",1);
    14.             PlayerPrefs.SetString ("loggedinplayer",myUsername);
    15.             PlayerPrefs.SetString("PlayerOne",myUsername);
    16.             PlayerPrefs.SetString("password",myPassword);
    17.             char[] delimiterChars = {':'};
    18.             string[] usertable = download.text.Split(delimiterChars);
    19.             print (usertable[0]);
    20.             if(usertable[0] == "successful login"){
    21.                 if (rememberMe){
    22.                     PlayerPrefs.SetInt("RememberUser",1);
    23.                     PlayerPrefs.SetString("RememberUserName",myUsername);
    24.                     PlayerPrefs.SetString("RememberPassword",myPassword);
    25.                 }
    26.                 else{
    27.                     PlayerPrefs.SetInt("RememberUser",0);
    28.                     PlayerPrefs.SetString("RememberPassword",myPassword);
    29.                 }
    30.                 Application.LoadLevel("onlinesetupmenu");
    31.             }
    32.             else{
    33.                 nameErrorMsg = "this name is taken\n please choose another name";
    34.             }
    35.         }
    36.     }
     
  2. Agent_007

    Agent_007

    Joined:
    Dec 18, 2011
    Posts:
    899
    Replace
    Code (csharp):
    1. if( download.error != null)
    with
    Code (csharp):
    1. if( !String.IsNullOrEmpty(download.error))
    and see if it works any better
     
  3. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    oh - totally this! 8) There were some changes in how we treat strings from native-to-mono internally along with WWW impl changes - so now you should check WWW.error in "proper" way, as in String.IsNullOrEmpty
     
  4. earthcrosser

    earthcrosser

    Joined:
    Oct 13, 2010
    Posts:
    121
    My problem was solved by upgrading from 4.3.3 to Unity 4.3.4 :)
    But now I'm reading this ^^ :) So I will also replace my if statement with the "proper" check :) Thanks you both!!! I heart Unity Forums!