Game Development Reference
In-Depth Information
w_form.AddField("score", score);
//Sending the user name
w_form.AddField("name", name);
//Start waiting for the response back from the server
StartCoroutine(WaitingForResponse(new WWW(PHPUrl, w_form),
null));
}
3. Create the WaitingForResponse( www : WWW, callback : Function)
: IEnumerator funcion as menioned previously. Let's coninue from ater the
SendScore() funcion and type it as follows:
//Waiting for the response back from the server
public function WaitingForResponse( www : WWW, callback :
Function) : IEnumerator {
yield www;
if (www.error == null) {
Debug.Log("Successful.");
} else {
Debug.Log("Failed.");
}
if (callback != null) {
callback(www.text);
callback = null;
}
//Clears data
www.Dispose();
}
4. We already have the funcion to send; now we need to load the data from the
server, so we will create the GetScores() funcion to load the user's score data
from the server. Let's type it as follows:
//Getting the score from the server
public function GetScores() : void {
b_loaded = false;
var w_form : WWWForm = new WWWForm();
//Telling PHP that the user is loading the data
w_form.AddField("action", "GetScore");
//Start waiting for the response back from the server
StartCoroutine(WaitingForResponse(new WWW(PHPUrl, w_form),
LoadXMLData));
}
 
Search WWH ::




Custom Search