- Home /
getting high score of game from asp.net page
I have implemented a script to get latest score from asp.net page using below code
IEnumerator GetScores()
{
//gameObject.guiText.text = "Loading Scores";
WWW hs_get = new WWW(highscorePageURL);
yield return hs_get;
if (hs_get.error != null)
{
print("There was an error getting the high score: " + hs_get.error);
}
else
{
lbl1.text = hs_get.text;
// gameObject.guiText.text = hs_get.text; // this is a GUIText that will display the scores in game.
}
}
it is getting score but also gets html code of this page too. i have attached screenshot what it returns
can anyone figure out what should i do to get only score instead of full code of page ?
thanks in advance
Answer by aeronicweb · Jan 09, 2014 at 10:50 AM
After many efforts i fixed it my self. I used regular expression in unity3D to separate value for this like
public void matchh()
{
string txt = newscore;
//string txt="adasdadasd <bst>60</bst> asedsadadasddasd sdasdadadas";
Regex r = new Regex(re1+re2+re3+re4+re5+re6+re7+re8+re9+re10+re11+re12+re13,RegexOptions.IgnoreCase|RegexOptions.Singleline);
Match m = r.Match(txt);
if (m.Success)
{
String c1=m.Groups[1].ToString();
String c2=m.Groups[2].ToString();
String c3=m.Groups[3].ToString();
String c4=m.Groups[4].ToString();
String c5=m.Groups[5].ToString();
String int1=m.Groups[6].ToString();
String c6=m.Groups[7].ToString();
String c7=m.Groups[8].ToString();
String c8=m.Groups[9].ToString();
String c9=m.Groups[10].ToString();
String c10=m.Groups[11].ToString();
String c11=m.Groups[12].ToString();
lbl1.text= (int1.ToString());
}
}
and now its showing only score instead of whole html code
Answer by nikroth · Jan 09, 2014 at 10:50 AM
You can't get a single element with a command. You get the html code.
HTML is in XML format so you can remove the first line and then parsi it as an XML and get the element you want.
Or you can place the score in a hidden field and with String.IndexOf you can find the position where the value is and then parse it to int.
Just accept that you have a text and you have to find your value in the text.