Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by knopa11 · Dec 27, 2017 at 03:38 PM · unity 5webglerror messagedatabasehtml5

Trying to read out of a website and wan't to store the value. Works perfect in Unity and Desktop Build. Any Ideas?

Error Code: FormatException: Input string was not in the correct format.

I got the string from the website and converted it to a float (theres just a single value on the website). It works in Unity and in Desktop build, but just not on WebGL.

My Script:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class DataLoader : MonoBehaviour {

 private int steps;
 private string stepsString;
 public int whileNumber = 1;
 private float kilometers;
 private float stepsFloat;

 // Use this for initialization
 IEnumerator Start () {
     while (whileNumber == 1)
     {
         WWW databaseSteps = new WWW("http://schrittzaehler.rapperswil-jona.ch/globalsteps.php");
         yield return databaseSteps;
         stepsString = databaseSteps.text;
         steps = int.Parse(stepsString);
         stepsFloat = steps;
         kilometers = stepsFloat * 0.62f / 1000;
         PlayerPrefs.SetFloat("kilometersTravelled", kilometers);
         Debug.Log(kilometers);
         yield return new WaitForSeconds(1);
     }
 }
 
 // Update is called once per frame
 void Update () {

 }

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Larry-Dietz · Dec 28, 2017 at 05:53 AM

FormatException: Input string was not in the correct format means that whatever value it read from the website, was NOT a float value, nor could it be made into one. Most likely cause would be an alpha result being sent from the web page.

Verify your URL you are using. The one in your code above returns a DNS error when I tried to hit it.

My best recommendation is to verify your URL, and before you try converting it into a float, throw in a debug log to show you what was received, so you can confirm you are actually receiving a number.

Hope this helps, -Larry

Comment
Add comment · Show 3 · 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 knopa11 · Dec 28, 2017 at 06:25 AM 0
Share

I got the number already in the Debug.Log and it's just a single php script with an echo on the website which i did on my own. The strange thing is that's perfectly working on every platform (inside unity, on pc build...) but just not in the html5 format. I tried to create a new project with just a script which gets the number and gives it as an output, but it's not working either on html5 (works again on pc and inside unity). $$anonymous$$aybe Unity WebGL doesn't support the WWW function (WWW databaseSteps = new WWW("http://schrittzaehler.rapperswil-jona.ch/globalsteps.php")

avatar image Larry-Dietz knopa11 · Dec 28, 2017 at 06:42 AM 0
Share

That is odd.

I know the WWW routines work in WebGL. I have an app running under WebGL that hits a PHP script much the way yours does, to get an entry from a database on my server, and it doesn't have any problems.

In your test, just grabbing the results of the call to the PHP script, and displaying what was received. What was the error you got? The initial error was a format exception when trying to convert to float. If your 2nd test didn't try this conversion, I would expect a different error.

-Larry

avatar image knopa11 Larry-Dietz · Dec 28, 2017 at 08:22 AM 0
Share

I tried it with without the while loop and without the int.Parse and it worked again in Unity but not on WebGL (there's no Error code anymore, but there's no text/number). I also tried to read a value out of a .txt file and it also worked on pc build and in unity but again not in webgl. $$anonymous$$aybe Unity WebGL has a general problem with reading out of files/websites. I'm trying to update my Unity / WebGL, hope it works.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

149 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 5.6 Webgl Photon Spawn Error 0 Answers

Communication between WebGL and .jslib 1 Answer

Embed Unity Webgl game to wix website 1 Answer

Please Help! CommandInvokationFailure and other build errors 1 Answer

Bool condition is always resulting in false even when it seems impossible to be false even using debug lines to check 4 Answers


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