x


Before updating to Windows 10 you may need to return your Pro license. More information here

Problem with yield and WWW() inside Start() function

Hi, I'm testing some code to get xml data from a server using the WWW() function from here http://unity3d.com/support/documentation/ScriptReference/WWWForm.html The problem is that Unity'console keeps telling me: A local variable named `textFromServer' is already defined in this scope. This makes me think that it can't be used the instruction 'yield' inside the start() function... because this problem doesn't happen when I delete the line that has yield written but the file needs time to be downloaded.

// Use this for initialization //void Start () { Before IEnumerator Start() {

     //Load XML data from a URL
 string url = "http://www.domain.com/file.xml?argumen1=98769";

     WWW textFromServer = new WWW(url);

 //Load the data and yield (wait) till it's ready before we continue executing the rest of this method.
     //yield textFromServer; Before
         yield return textFromServer;
     if (textFromServer.error == null) {

     //Sucessfully loaded the XML
     Debug.Log("Loaded following XML " + textFromServer.text);
     }
 }

Thanks for your help.

more ▼

asked Jan 20, 2011 at 12:33 AM

avatar image

ChuckSaldana
74 9 9 18

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You're trying to use Javascript syntax in C#. The correct syntax is "yield return textFromServer;".

more ▼

answered Jan 20, 2011 at 12:45 AM

avatar image

Eric5h5
121k 79 361 774

Thank you, I just found something missing: the return type of Start should change to IEnumerator also.

Jan 20, 2011 at 12:50 AM ChuckSaldana
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x970

asked: Jan 20, 2011 at 12:33 AM

Seen: 5117 times

Last Updated: Jan 20, 2011 at 12:51 AM