- Home /
C# Yield in a Method with Return a value
hello :)
I'm trying to yield until a www is finished and than return a specific answer like:
public IEnumerator checkBetaKey(string betacode, string betaname){
form = new WWWForm ();
form.AddField ("betacode", betacode);
form.AddField ("betaname", betaname);
headers = form.headers;
rawData = form.data;
//set Auth Key in Type: "Basic : Name:Key"
headers ["Authorization"] = "Basic " + System.Convert.ToBase64String (System.Text.ASCIIEncoding.ASCII.GetBytes(betaname + ":" + betacode));
www = new WWW (url, form, headers);
yield return www;
if (www.error != "") {
return false;
} else {
if (www.text == "true") {
return true;
} else {
return false;
}
}
}
but there are some Errors: Argument #2' cannot convert UnityEngine.WWWForm' expression to type byte[]' The best overloaded method match for UnityEngine.WWW.WWW(string, byte[], System.Collections.Hashtable)' has some invalid arguments
Cannot implicitly convert type System.Collections.IEnumerator' to bool' (When I try to use the Method).
Have you any ideas? :)
Answer by Teravisor · Feb 07, 2016 at 10:39 PM
First I think you've meant to call www = new WWW(url, form);
Next you can't return false or return true from coroutine as its return value is IEnumerator. Consider setting variable defined in class with its return value instead.
Your answer
Follow this Question
Related Questions
Using a method to get the string from a download. 3 Answers
Why does nothing happen after yield return www 0 Answers
Ienumerator return string 0 Answers
Handle Blank Response From Web Server 0 Answers
yield return www probem 1 Answer