- Home /
yield return WWW.text not downloading???
Basically i'm doing a simple username and password script from a mysql database but when i get the data then it keeps giving me a strange error: UnityException:
WWW is not ready downloading yet
UnityEngine.WWW.get_text () (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/Utils.cs:171)
DatabaseLoginManager+<Start>c__Iterator0.MoveNext () (at Assets/DatabaseLoginManager.cs:31)
I don't see the issue, here's my code:
using UnityEngine;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
public class DatabaseLoginManager : MonoBehaviour {
public string url;
public string username;
public string password;
public UnityEngine.UI.InputField usernameInput;
public UnityEngine.UI.InputField passwordInput;
public WWW www;
public string UserAndPass;
// Update is called once per frame
public GameObject ErrorMesage;
void Update ()
{
username = usernameInput.value;
password = passwordInput.value;
if(Input.GetKeyDown(KeyCode.Return))
{
url = "http://tgsfps.x10host.com/GAMEDB/TGSFPS/Retrieve.php?username=" + username;
UserAndPass="User="+username+"-"+"Pass="+password;
}
username = usernameInput.value;
password = passwordInput.value;
}
IEnumerator Start()
{
WWW www = new WWW (url);
yield return www.text;
UserPassCheck ();
}
void UserPassCheck()
{
}
}
Answer by Bonfire-Boy · Jan 29, 2015 at 01:18 PM
(This relates to the revised code)
The update function is looking at the member field www, which is
a) never being set (your Start function sets a local www variable instead - this is what fafase's comment is hinting at)
and
b) not being checked in Update to see if it's returned.
I would probably
1) remove the WWW member variable altogether,
and
2) put the code that processes the returned WWW object in the function that calls it (ie after the "yield return www").
That way you know you're only ever processing the WWW object after it's returned. Best to check that it's succeeded before using www.text, too.
i removed it and i keep getting this malformed url error, i don't understand why because all i need is the www.text
$$anonymous$$y suggestion involved 2 parts, did you do the second as well?
What happens if you put
Debug.Log(www.text);
immediately after the line
yield return www;
?
It's not at all clear what you're trying to do, so it's difficult to help further.
I think you need to learn to get something simple working before adding complexity.
For example, to start with you could remove ALL the www and url code from everywhere except the function with the WWW object in it. Set the URL there, do the WWW call, look at the reply. Once you've got that working you can look at setting the URL dynamically.
Specifically, try this...
void Start() { StartCoroutine(doWWW()); } IEnumerator doWWW() { string url = "(insert your url here)"; WWW www = new www(url); yield return www; Debug.Log(www.text); }
well, I implemented it and that nearly got it working but now i get this error message:
NullReferenceException: Object reference not set to an instance of an object
DatabaseLogin$$anonymous$$anager.ValidateCheck () (at Assets/DatabaseLogin$$anonymous$$anager.cs:18)
DatabaseLogin$$anonymous$$anager.Update () (at Assets/DatabaseLogin$$anonymous$$anager.cs:39)
With this code:
using UnityEngine;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
public class DatabaseLogin$$anonymous$$anager : $$anonymous$$onoBehaviour {
public string username;
public string password;
public UnityEngine.UI.InputField usernameInput;
public UnityEngine.UI.InputField passwordInput;
public WWW www;
public string UserAndPass;
// Update is called once per frame
public GameObject Error$$anonymous$$esage;
void ValidateCheck()
{
UserAndPass = "User=" + username + "-Pass=" + password;
if (UserAndPass == www.text)
{
Debug.Log ("Successful Login");
}
else
{
Instantiate(Error$$anonymous$$esage);
}
}
void Update ()
{
username = usernameInput.value;
password = passwordInput.value;
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Return))
{
ValidateCheck();
}
}
IEnumerator doWWW()
{
string url = "http://tgsfps.x10host.com/GA$$anonymous$$EDB/TGSFPS/Retrieve.php?username="+ username;
WWW www = new WWW(url);
yield return www;
Debug.Log (www.text);
}
}
Your answer
Follow this Question
Related Questions
Best/Cheapest Way To Have Online Accounts On PC? 1 Answer
Unity 2017 freezes on login page 0 Answers
How to change from login scene to character costum scene ? 5 Answers
Firebase Saves and retrieves data perfectly on editor, but does't work on mobiles 0 Answers
WWW (webrequest)not working in windows8.1 app store build 0 Answers