- Home /
error CS0200: Property or indexer `UnityEngine.WWW.error' cannot be assigned to (it is read only)
Topened my script this morning and unity freaked out: private IEnumerator RegisterAcount(){ WWWForm Form = new WWWForm(); Form.AddField("Username", Username); Form.AddField("Pass", Pass);
WWW RegisterAccountWWW = new WWW(RegisterURL, Form);
yield return RegisterAccountWWW;
if(RegisterAccountWWW.error = !null){
Debug.Log("Cannot Connect");
} else {
Isloggedin.SetActive(true);
IsNotLoggedIn.SetActive(false);
Debug.Log("IS LOGGED IN... BITCHIES");
}
} // End IEnumerator.
Answer by NerdClown · Oct 16, 2015 at 10:00 AM
Maybe it should be like this?
if (RegisterAccountWWW.error != null)
{
//...
}
In the times when that doesnt work, just check for presence.
if(thingToBeChecked != null)
if(thingToBeChecked)
Answer by Garazbolg · Oct 16, 2015 at 08:16 AM
Your trying to affect a value to a WWW.error in :
if(RegisterAccountWWW.error = !null){
you are just missing a equal sign like this :
if(RegisterAccountWWW.error != null){
// or better
if (!string.IsNullOrEmpty(RegisterAccountWWW.error)){
'=' equal affectation (this = that; this become that)
'==' equal comparaison (this == that; is this equal to that)
Are you sure that your first alternative, if(RegisterAccountWWW.error == !null)
, works?
I don't think you can apply the ! operator to null.
Oh you're right.
Also I forgot error was a string, so what you should actually use is :
if (!string.IsNullOrEmpty(RegisterAccountWWW.error)){
Yep, IsNullOrEmpty is the best choice. However as far as i know it's usually null when no error happens, but IsNullOrEmpty is the better choice and your ready for a possible internal change of the WWW class in the future ^^.
btw: $$anonymous$$aybe edit your answer, add this example and remove the wrong one before you get a downvote? :)
For future reference, I think it's worth pointing out that the word "affectation" doesn't mean what you think it does (it actually means something more like "pretending to have a quality"). The standard word for what you mean there is "assignment".
Oh Thanks you i won't do it again, i just assumed it was like in my native language (French) where "assign a value" is "affecter une valeur", but apparently not.
Your answer
Follow this Question
Related Questions
(PLEASE HELP) hi guys! i have a problem with my Score text 1 Answer
My ball in pong passes through the paddles. 3 Answers
Add all objects of a type to a list before runtime 1 Answer
"There is no 'GameObject' attached to the "x" game object' 2 Answers
When pressing the space bar, the Unity editor detects it as the "O" key, how can I solve this? 2 Answers