1 Replies - 6117 Views - Last Post: 07 January 2013 - 11:55 PM Rate Topic: -----

#1 optix212  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 27
  • View blog
  • Posts: 509
  • Joined: 10-October 09

Problem with Int.Parse

Posted 07 January 2013 - 11:22 PM

So, I'm building a video game with the Unity3D API, and the error code that it's throwing me seems to be universal to all of C# (meaning that it is not API-specific).

What I'm doing is having all of the highscores on my game be sent to a server, and then transmitting them back to the game. The exception reads as follows: "FormatException: Input string was not in the correct format."

It says it's coming from the line of code in which I utilize the Int.Parse function (one of which I have never used until now).

Here is the code:
	IEnumerator GetScores()
    {
		//this.gameObject.guiText.text="Loading Scores";
        //gameObject.guiText.text = "Loading Scores";
		print ("Loading Scores");
        WWW hs_get = new WWW(highscoreURL);
        yield return hs_get;
		
		int index=0; // Index of my loop
		print(HighNumbers.Length);
		string sTemp=hs_get.text; // putting the highscore text into a string called sTemp
		string[] lines = Regex.Split(sTemp, " "); // Splitting it based on spaces - should probably be changed to | but fuck it i'll do that later
			 
    	
			foreach (string line in lines){
			int i;
			HighNumbers[index]=int.Parse(lines[index]); // putting the content of line (which was split based on spaces) into index of HighNumbers
			
			print(HighNumbers[index]); 
			index++;
			ScoresLoaded = true;
			
			
		}
		
			
        }



Some people on the Unity forums told me to try Int.TryParse, but I don't know exactly how that would be implemented specifically for this code.. I have seen some examples of TryParse, but nothing that I could actually figure out how to utilize for this script. So, they eventually told me to go to a c# specific forum, and since I've been coming here for years now, I figured this would be a great place to post. ^_^

All I'm asking for is a little guidance. A simple push in the right direction would more than suffice. Thank you!

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with Int.Parse

#2 optix212  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 27
  • View blog
  • Posts: 509
  • Joined: 10-October 09

Re: Problem with Int.Parse

Posted 07 January 2013 - 11:55 PM

Wow.. I've been stuck on this for 2 days now, and OF COURSE, I figure this out 30 minutes after I post on here..

int.TryParse(lines[index], out HighNumbers[index]);



The problem??

I wasn't deleting the "HighNumbers[index]=" when I would put tryParse... DURRP!

This post has been edited by optix212: 07 January 2013 - 11:57 PM

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1