Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Nov 14, 2012 at 04:03 PM by Fattie for the following reason:

Other

avatar image
0
Question by shaystibelman · Mar 08, 2012 at 10:38 AM · floatnumberparse

invalid format exception when parsing float

Hello all,

I've been creating a tele-transportation script that gets the coordinates from an sql server based database. After downloading the data and splitting it with Regex.Split, I have to parse it into a float so the vector3 gets the numbers.

My problem is that, even though it works and during gameplay everything functions, in the console I get format exception messages.

"FormatException: Invalid format. System.Double.Parse (System.String s, NumberStyles style, IFormatProvider provider)"

 function teletransportation(searchname){
     //create the form with the name of the point to which we want to teletransport
     var sendPoint : WWWForm = new WWWForm();
         sendPoint.AddField("PointName",searchname);
         
     //send the WWWForm via WWW
     var getCoords : WWW = new WWW("../DataBase/FindPoint.php",sendPoint);
     yield getCoords; //Wait for the data to return
     
     //split downloaded data
     var received_data = Regex.Split(getCoords.text/*data*/,"</next>");
     //divide split data into vars 
     pointCoords.x = float.Parse(received_data[0]);
     pointCoords.y = float.Parse(received_data[1]);
     pointCoords.z = float.Parse(received_data[2]);
 
     //traslation function
     gameObject.Find("Player").transform.position.x = pointCoords.x;
     gameObject.Find("Player").transform.position.y = pointCoords.y;
     gameObject.Find("Player").transform.position.z = pointCoords.z;
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by shaystibelman · Mar 08, 2012 at 11:06 AM

Ok, I don't know WHY that works, but I've looked at other answers and found that parseFloat() doesn't give that error, so I just used that and I no longer receive the error.

Sorry 'bout that :)

*note: if the admins want to delete this question, feel free.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Bunny83 · Mar 08, 2012 at 11:10 AM

Well, wouldn't it be interesting how your returned data looks like? That's the real problem.

I guess it's something like:

 "<next>10</next>  <next>20</next>  <next>30</next>"

If you split it at "``" the 4 strings would look like this:

 received_data[0] = "<next>10"    
 received_data[1] = "  <next>20"    
 received_data[2] = "  <next>30"
 received_data[3] = ""

Why do you use xml for returning 3 values? Just 3 comma-seperated-values would be enough. If you have to use xml, why do you parse the xml string manually? There are many xml parsers out there.

Some further side-notes:

  • I'm not sure if you need pointCoords outside of the function, but it looks like it shoule be alocal variable.

  • pointCoords is a vector3, so why do you assign it component by component to Transform.position? gameObject.Find("Player").transform.position = pointCoords; is enough.

  • Find() is a static function of GameObject and you should use the classname instead of an instance. In other words : gameObject.Find( --> GameObject.Find(

  • GameObject.Find is a quite low function. It's ok to call it once every level change, but avoid it in Update() or other cyclic called functions.

  • To see what float.Parse() actually have to parse, you can put a Debug.Log(received_data[0]); in your code.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image shaystibelman · Mar 08, 2012 at 11:45 AM 0
Share

no, the data was actually split right, i had only the numbers, since in the php creating the array i wrote: echo xValue."";

anyway, i have already resolved it usint parseFloat() ins$$anonymous$$d.

thanks!

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Float.Parse question 1 Answer

Unity3D editor not allowing large floats as input 1 Answer

how to keep fraction number ??? 1 Answer

Convert positive float to negative? 5 Answers

Float, make percentage 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges