- Home /
Download a WWW int? Or convert?
I need to convert a text (numbers only) i downloaded with WWW and then convert it to a int. Here is my current code but it is not working: using UnityEngine; using System.Collections;
public class FetchXP : MonoBehaviour {
public GUISkin GUISkin;
public string url = "url";
IEnumerator Start (){
PlayerPrefs.DeleteKey("xp");
WWWForm form = new WWWForm();
form.AddField( "username", PlayerPrefs.GetString("Username"));
WWW download = new WWW( url, form );
yield return download;
if((!string.IsNullOrEmpty(download.error))) {
print( "Error downloading: " + download.error );
} else {
Debug.Log(download.text);
int.Parse(download.text);
PlayerPrefs.SetInt("xp", download.text);
}
}
Errors:
1.(18,37): error CS1502: The best overloaded method match for UnityEngine.PlayerPrefs.SetInt(string, int)' has some invalid arguments 2.(18,37): error CS1503: Argument
#2' cannot convert string' expression to type
int'
Comment
Best Answer
Answer by PAEvenson · Jun 18, 2013 at 11:10 AM
int parsedInt = int.Parse(download.text);
PlayerPrefs.SetInt("xp", parsedInt );
Your answer
Follow this Question
Related Questions
int to string, weird string value? 1 Answer
convert string to int 0 Answers
Convert int to string 2 Answers
c# convert int to string 2 Answers