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

Simple Co Routine and WWW variable issue going from Js to C#

Discussion in 'Scripting' started by FisherM, Aug 11, 2014.

  1. FisherM

    FisherM

    Joined:
    Dec 28, 2013
    Posts:
    366
    So I am converting the Javascript script on this page :
    http://forum.unity3d.com/threads/tutorial-unity-and-php-login-script-simple-but-useful.24721/

    I have had issues with yield and replaced it with a co routine, not sure if I did it correctly

    I am also getting an error on line 28. as follows
    help much appreciated
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class LoginHandler : MonoBehaviour {
    5.     string formNick = "";
    6.     string formPassword = "";
    7.     string URL = "url";
    8.     string formText;
    9.     WWW w;
    10.     // Use this for initialization
    11.     void Start () {
    12.    
    13.     }
    14.    
    15.     // Update is called once per frame
    16.     void Update () {
    17.    
    18.     }
    19.  
    20.     public IEnumerator WaitForWWW() {
    21.         yield return this.w; //we wait for the form to check the PHP file, so our game dont just hang
    22.     }
    23.  
    24.     public void Login(){
    25.         WWWForm form = new WWWForm(); //here you create a new form connection
    26.         form.AddField( "myform_nick", formNick );
    27.         form.AddField( "myform_pass", formPassword );
    28.         w = WWW(URL, form); //here we create a var called 'w' and we sync with our URL and the form
    29.         StartCoroutine(WaitForWWW());
    30.  
    31.         if (w.error != null) {
    32.             print(w.error); //if there is an error, tell us
    33.         } else {
    34.             print("Test ok");
    35.             formText = w.data; //here we return the data our PHP told us
    36.             w.Dispose(); //clear our form in game
    37.         }
    38.        
    39.         this.formNick = ""; //just clean our variables
    40.         this.formPassword = "";
    41.     }
    42. }
    43.  
     
  2. FisherM

    FisherM

    Joined:
    Dec 28, 2013
    Posts:
    366
    Still really needing some assistance with this
     
  3. DoomSamurai

    DoomSamurai

    Joined:
    Oct 10, 2012
    Posts:
    159
    line 28 ; w = new WWW(URL, form);
     
  4. FisherM

    FisherM

    Joined:
    Dec 28, 2013
    Posts:
    366
    I am getting the following error

    Code (CSharp):
    1. 500 Internal Server Error
    2. UnityEngine.MonoBehaviour:print(Object)
    3. LoginHandler:Login() (at Assets/Resources/LoginHandler.cs:34)
    4. System.Reflection.MethodBase:Invoke(Object, Object[])
    5. dfEventBinding:callProxyEventHandler(Object[]) (at Assets/Daikon Forge/DataBinding/Scripts/dfEventBinding.cs:581)
    6. dfEventBinding:MouseEventProxy(dfControl, dfMouseEventArgs) (at Assets/Daikon Forge/DataBinding/Scripts/dfEventBinding.cs:236)
    7. dfControl:OnClick(dfMouseEventArgs) (at Assets/Daikon Forge/DFGUI/Scripts/Controls/dfControl.cs:1678)
    8. dfButton:OnClick(dfMouseEventArgs) (at Assets/Daikon Forge/DFGUI/Scripts/Controls/dfButton.cs:686)
    9. MouseInputManager:ProcessInput(dfInputManager, IInputAdapter, Ray, dfControl, Boolean) (at Assets/Daikon Forge/DFGUI/Scripts/Internal/Input/dfInputManager.cs:1654)
    10. dfInputManager:processMouseInput() (at Assets/Daikon Forge/DFGUI/Scripts/In
     
  5. DoomSamurai

    DoomSamurai

    Joined:
    Oct 10, 2012
    Posts:
    159
    500 internal Server Error indicates an error with the web server. Are you sure the url you are using is correct?
     
  6. FisherM

    FisherM

    Joined:
    Dec 28, 2013
    Posts:
    366
    solved thanks
    solve th