- Home /
yield www javascript
I have to get an array from an URL and i am using yield www. When i run the application in game mode it works but when i run it on the server my data doesn't show.
function Start(){
StartCoroutine("getData");
}
function getData(){
var www : WWW = new WWW("adress");
yield www;
myHash = eval(www.text);
//yield WaitForSeconds(1.0);
}
function OnMouseDown(){
gameObject.Find("wallName").guiText.text = myHash[wallName];
}
I tried without coroutine and the same result : ok in unity, nothing online.
I am going to assume that by "application in game mode" you mean your game running in the Unity IDE and by "on the server" you mean the app running as webplayer in the browser.
How does the data not show? How do you output the data? With print (its not in your code)? $$anonymous$$eep in $$anonymous$$d that there is no inbuilt console in webplayer builds.
There is also a concurrency problem when using WWW in a webplayer build. $$anonymous$$ake sure you don't try to catch the "download ready" event (with some kind of loop), because the webplayer than will never fire it and will hang.
"application in game mode" = in unity "on the server" = online (i build a player for a website ) I use the data retrieved to set some guiText.text.
I edited my code and added the use of the data from www.
Answer by softrare · Nov 08, 2011 at 09:59 AM
What if you put it like this?
function getData() {
var www : WWW = new WWW("adress");
yield www;
myHash = eval(www.text);
gameObject.Find("wallName").guiText.text = myHash[wallName];
}
I know that is not what you are trying to do, but does it work?
it doesn't work. doesn't matter what button i press the result is the same. (I have 4 buttons and when i press one i want to get the name of it from www).
other ideas ?
What about
function getData() {
var www : WWW = new WWW("adress");
yield www;
gameObject.Find("wallName").guiText.text = www.text;
}
This is the most basic case. If that does not work, there is something wrong with the connection or the output method I guess.
Also I myself ealier had problems with using WWW in the webplayer and I noticed that it takes longer for the webplayer to receive data, so you maybe would have to wait a longer time before expecting a result to come up (in case the amount of data your transmit is big).
I just remembered something else: be sure that the webplayer is hosted on the same server (and same domain) as the target server script. Otherwise the data will indeed not be transmitted due to browser limitations.
i receive an array of 476 characters. i don't think the amount of data is a problem. i think the WEBPlayer doesn't work very good with yield because if i build a standalone exe it work great.
other ideas ?
it's something wrong with my filesystem. the file that i want to get information from it's on the same server as the player. i will try other approach and post a result. thanks softrate.
Your answer
