- Home /
www array, help?
OK so i need to read a string, divide it to an array, the string will contain urls that i need to download and put in another array, and it will use eval() to execute them. so here's my code:
var mods:String;
var modlist:String[];
var temp1:int = 0;
var www:WWW[];
function Start() {
mods = PlayerPrefs.GetString("mods");
modlist = mods.Split(","[0]);
while (temp1 < modlist.length) {
www[temp1] = new WWW (modlist[temp1]);
yield www[temp1];
temp1++;
}
temp1 = 0;
var modtext:String[];
while(temp1 < modlist.length) {
modtext[temp1] = www[temp1].text;
eval(modtext[temp1]);
}
}
then it says:
(wrapper stelemref) object:stelemref (object,intptr,object) mods+$Start$24+$.MoveNext () (at Assets/Scripts/mods.js:34)NullReferenceException: Object reference not set to an instance of an object
Try formatting your post so it is readable next time. :)
Answer by rutter · Mar 31, 2012 at 11:59 PM
First thing I noticed:
var www:WWW[];
You've declared an array reference, but did you ever assign a value?
If you find built-in arrays confusing, you might want to try Unity's `Array` class.
Also, looking at this bit of your error message:
Assets/Scripts/mods.js:34
This indicates the error is occurring on line 34 of a file named mods.js
. Which line is that? Is it included in your code sample, above?
Finally, looking at this bit of your question:
it will use eval() to execute them
Does UnityScript support eval()? In a quick search, it seems like support for it was partially or completely broken since 3.x. Even if it's something you could do, I have a feeling it's probably not a good idea.
ok so ok here's the full code: http://pastebin.com/Ua58enu$$anonymous$$ and yes i assign www:WWW[]:
while (temp1 < modlist.length) { ---> www[temp1] = new WWW (modlist[temp1]); <--- yield www[temp1]; temp1++; }
and if eval() is not working anymore.. how am i going to implement mods?
@dvidunis: No you don't understand what he meant. You create several WWW objects, but not the array itself.
function Start() {
mods = PlayerPrefs.GetString("mods");
modlist = mods.Split(","[0]);
www = new WWW[modlist.length]; // create the array!!
temp1 = 0;
while (temp1 < modlist.length) {
www[temp1] = new WWW (modlist[temp1]);
yield www[temp1];
temp1++;
}
Arrays have a fix size which have to be specified when you create the array. This size can't be changed.
Your answer
Follow this Question
Related Questions
Issue with WWW-Class' slow response time 2 Answers
WWW load mp3 GetAudioClip without stream,play only a part,then no sound. 0 Answers
www return empty text on android 0 Answers
How to contact a 3rd party server? 0 Answers
i think www blocks display thread 1 Answer