- Home /
How to Call a Number Using WWW and Actually Do Something With The Number (Please Read)
I have created a php page on my website that displays only a number, for example 3.25 and nothing else. Everything's running smoothly, i call the url, and in my Debug the number 3.25 displays perfectly. The problem is that I can't use that number to actually do anything. I need to be able to do something like
if (www.data >= 3.25) {
//do something
}
But in return, I keep getting this error in my console -
error CS0019: Operator >= cannot be applied to operands of type string and double
Thanks for the help in advanced, Heres my code:
 using UnityEngine;
 using System.Collections;
  using UnityEngine.UI;
    public class Example : MonoBehaviour {
 public Text myText;
 string url = "http://www.website.com";
 
 void Start () {
     WWW www = new WWW(url);
     StartCoroutine(WaitForRequest(www));
 }
 IEnumerator WaitForRequest(WWW www)
 {
     yield return www;
     // check for errors
     if (www.error == null)
     {
         Debug.Log("WWW Ok!: " + www.data);
         myText.text = www.data;
                  if (www.data >= 3.25) {
                   Debug.Log ("It Worked");
         }
     }  else {
         Debug.Log("WWW Error: "+ www.error);
     }     
 }
 
    }
Answer by Mikilo · Sep 01, 2015 at 05:45 AM
Hello!
www.data is deprecated, you should use www.text, which is more explicit.
Why more explicit? Because you can not compare a string and a number.
You need to parse your number. Like this:
 int.Parse(www.text) >= 3.25F
Notice the F in "3.25F", it means float, if you do not mention it, it will be a double.
Right on the money, thanks a lot $$anonymous$$ikilo i owe you one. One thing for others who have this issue. Ins$$anonymous$$d of int.Parse(www.text) >= 3.25f it should be float.Parse(www.text) >= 3.25f
You are welcome and true!
float.Parse is more relevant in this case.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                